Question problem in stored procedure

nitish

Member
Joined
Mar 14, 2012
Messages
6
Programming Experience
Beginner
Hi..I am developing a project
(c#.net) called mysql querybrowser..There is problem with stored procedure. Actually user will create and run stored procedure at run time...so in project creating is being done successfully but there is problem in calling stored procedure...because i have to pass the parameters at run time and if there is no parameter then no need to pass it...so i am not getting that how to do it....Plz help me asap....thanks...

I am providing the code here so you can get a little bit idea of it...


string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(connStr)) {
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "CALL MyProcedure(@MyParam1, @MyParam2);";
cmd.Parameters.AddWithValue("@MyParam1", 123);
cmd.Parameters.AddWithValue("@MyParam2", "blah");

conn.Open();
cmd.ExecuteNonQuery()
In cmd.commandText line how to add these myparam....because stored procedure is created run time....and also tell me the code in the case not providing any parameter..
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,274
Location
Sydney, Australia
Programming Experience
10+
You're trying to make this difficult when it's not. You already know what to do because you've already done it in your first post. All you have to do is what I told you to do in my first post. Make those changes and only those changes.
 
Top Bottom