如何调用MySql数据库中的多个存储过程

本文关键字:存储过程 数据库 MySql 何调用 调用 | 更新日期: 2023-09-27 18:02:02

我能够让这个程序与一个存储过程一起工作。在c#中可以从MYSQL调用多个存储过程吗?如果是这样,最有效的方法是什么?下面是我的代码片段,展示了我到目前为止所做的工作:

public static string RunSQL()
{
    // Here is where it is connecting to local host.
    string connStr = "server=localhost;user=xxxx;"
                     + "database=xxxx;port=3306;password=xxx;"
                     + "Allow User Variables=True";
    MySqlConnection conn = new MySqlConnection(connStr);
    // Here is where the connection gets opened.
    conn.Open();
    // Here I call the CN_renumber stored procedure.
    MySqlCommand CN_renumber = new MySqlCommand("CN_renumber", conn);
    CN_renumber.CommandType = System.Data.CommandType.StoredProcedure;
    object result = CN_renumber.ExecuteNonQuery();
    // Disconnect from local host.
    conn.Close();
    return result.ToString();
}

如何调用MySql数据库中的多个存储过程

您可以多次重用您的MySQLCommand对象,但在此之前您应该确保您调用了myCommand.Parameters.Clear();,然后再次分配新的Stored Procedure名称。

有例子的有用问题