Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# code error

C# code error

Scheduled Pinned Locked Moved C#
databasehelpcsharpmysqlsysadmin
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nitish_07
    wrote on last edited by
    #1

    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.

    L OriginalGriffO L A 4 Replies Last reply
    0
    • N nitish_07

      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.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • N nitish_07

        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.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        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 no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • N nitish_07

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          nitish_07 wrote:

          So plz tell me what should be the problem.

          Exactly the same as here[^]. Why have you reposted this in the C# forum when it is clearly a MySQL issue?

          speaking as ...

          1 Reply Last reply
          0
          • N nitish_07

            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.

            A Offline
            A Offline
            AmitGajjar
            wrote on last edited by
            #5

            Hi, Please post your code of stored procedure. -Amit

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups