【问题标题】:How to call multiple stored procedures in a MySql database如何在 MySql 数据库中调用多个存储过程
【发布时间】:2013-03-05 00:08:43
【问题描述】:

我能够让这个程序与一个存储过程一起工作。是否可以在 C# 中从 MYSQL 调用多个存储过程?如果是这样,最有效的方法是什么?这是我的代码的 sn-p 以显示我到目前为止所做的事情:

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();
}

【问题讨论】:

    标签: c# mysql sql-server-2008


    【解决方案1】:

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

    有用的问题,例如here

    【讨论】:

    • 我现在要做的是在 C# 中返回一个值,指示存储过程已完成。我正在考虑在最后一个要调用的 MYSQL 存储过程中做这样的事情: int status =0 if (proc.result >0) then { status = proc.result } label.status
    猜你喜欢
    • 1970-01-01
    • 2021-07-10
    • 2016-03-21
    • 1970-01-01
    • 2012-10-19
    • 2021-09-24
    • 1970-01-01
    • 2012-02-29
    • 2012-06-15
    相关资源
    最近更新 更多