C# code error
-
I have a button in my form and on click of that button I am writing this code.... OdbcCommand cmd ; cmd = new OdbcCommand(abc, cn); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); I have made a procedure named abc in database which is returning only one row from login table..So i am just checking that on click of that button my procedure should run but while debugging when i come to cmd.ExecuteQuery() it throws following error.. ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.77-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near abc() at line 1. So plz tell me what should be the problem.
-
I have a button in my form and on click of that button I am writing this code.... OdbcCommand cmd ; cmd = new OdbcCommand(abc, cn); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); I have made a procedure named abc in database which is returning only one row from login table..So i am just checking that on click of that button my procedure should run but while debugging when i come to cmd.ExecuteQuery() it throws following error.. ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.77-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near abc() at line 1. So plz tell me what should be the problem.
Hi, 1. the code as shown does not compile. What is abc? 2. if the data provides claims there is an error in your SQL, the least you should do is take an actual look at the SQL statement; and if you have to ask about it, then show it in your post. 3. you should call Dispose for objects that have such method once you don't need them any longer, in particular for SQL commands and connections. 4. are you sure your SP doesn't need parameters? if it does, I suggest you use OdbcParameter instances. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
I have a button in my form and on click of that button I am writing this code.... OdbcCommand cmd ; cmd = new OdbcCommand(abc, cn); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); I have made a procedure named abc in database which is returning only one row from login table..So i am just checking that on click of that button my procedure should run but while debugging when i come to cmd.ExecuteQuery() it throws following error.. ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.77-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near abc() at line 1. So plz tell me what should be the problem.
This is the code to execute a procedure with parameters:
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand com = new SqlCommand("proc_userinfo", con))
{
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@uid", "My new uid");
com.Parameters.AddWithValue("@uname", "My new uname");
com.Parameters.AddWithValue("@uip", "My new uip");
com.ExecuteNonQuery();
}In your case, you need to convert the abc to a string as an absolute minimum:
cmd = new OdbcCommand("abc", cn);
However, it is good practice to Dispose OdbcCommand objects: hence the
using
block in my example.Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
I have a button in my form and on click of that button I am writing this code.... OdbcCommand cmd ; cmd = new OdbcCommand(abc, cn); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); I have made a procedure named abc in database which is returning only one row from login table..So i am just checking that on click of that button my procedure should run but while debugging when i come to cmd.ExecuteQuery() it throws following error.. ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.77-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near abc() at line 1. So plz tell me what should be the problem.
-
I have a button in my form and on click of that button I am writing this code.... OdbcCommand cmd ; cmd = new OdbcCommand(abc, cn); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); I have made a procedure named abc in database which is returning only one row from login table..So i am just checking that on click of that button my procedure should run but while debugging when i come to cmd.ExecuteQuery() it throws following error.. ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.77-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near abc() at line 1. So plz tell me what should be the problem.
Hi, Please post your code of stored procedure. -Amit