2013-03-04 76 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

相關問題