2013-03-04 75 views
1

我能够使此程序使用一个存储过程。是否有可能从C#中的MYSQL调用多个存储过程?如果是的话,那么最有效的方式是什么?这里是我的代码片段显示什么我迄今所做:如何在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

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

与例如,有用的问题here

+0

我寻找现在要做的是回到在C#中,表明该存储过程已完成的值。 我想做着最后的MYSQL中是这样的存储过程被称为: INT状态= 0 如果(proc.result> 0)则{ 状态= proc.result } label.status – user2132252 2013-03-07 14:46:26

相关问题