簡體   English   中英

如何在MySql數據庫中調用多個存儲過程

[英]How to call multiple stored procedures in a MySql database

我能夠使該程序與一個存儲過程一起使用。 是否可以在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();
}

您可以多次重用MySQLCommand的對象,但在此之前,請確保調用myCommand.Parameters.Clear(); MySQLCommand ,然后再次分配新的Stored Procedure名稱。

與例如,有用的問題在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM