1

I am able to get this program to work with one stored procedure. Is it possible to call multiple stored procedures from MYSQL in C#? If so what is the most efficient way of doing so? Here is a snippet of my code to show what I've done thus far:

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();
}
Kjartan
  • 18,591
  • 15
  • 71
  • 96
user2132252
  • 49
  • 2
  • 9

1 Answers1

0

You can reuse your object of MySQLCommand multiple times, but before that you should make sure you call myCommand.Parameters.Clear();, then assign the new Stored Procedure name again.

Useful question with example here

Community
  • 1
  • 1
Muhammad Hani
  • 8,476
  • 5
  • 29
  • 44
  • What I am looking to do now is to return a value in C# indicating that the stored procedure has completed. I was thinking of doing something like this within the last MYSQL stored procedure to be called: int status =0 if (proc.result >0) then { status = proc.result } label.status – user2132252 Mar 07 '13 at 14:46