我能够让这个程序使用一个存储过程。是否可以在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();
}
答案 0 :(得分:0)
您可以多次重复使用MySQLCommand
的对象,但在此之前,您应确保拨打myCommand.Parameters.Clear();
,然后再次指定新的Stored Procedure
名称。
示例here
的有用问题