OdbcCommand exception - MySQL

Discussion in 'ASP .Net' started by Alan T, Jul 20, 2010.

  1. Alan T

    Alan T Guest

    Hi,
    I am using MySQL 5 and installed MySQl ODBC driver.

    I have a stored procedure, AddEmployee stored procedure:
    DELIMITER $$
    CREATE
    PROCEDURE `myCompany`.`AddEmployee`(EmployeeID VARCHAR(36),
    EmployeeGroup VARCHAR(10), EmployeeName VARCHAR(50))
    BEGIN
    INSERT INTO EmployeeTable (ID, Group, Name) VALUES ( EmployeeID ,
    EmployeeGroup , EmployeeName );
    END$$
    DELIMITER ;

    I tried to call for testing in a MySQL management tools.
    call AddEmployee('12345', 'Sales', 'Helen Smith')

    It works to insert a new record into the table.


    I got my method to insert a record to a table:

    protected void ExecuteNonQuery()
    {
    OdbcConnection cnx = null;
    cmd = null; //Avoids "Use of unassigned variable" compiler error
    try
    {
    // GetConnectionString returns MySQL connection string
    cnx = new OdbcConnection(GetConnectionString());
    cnx.Open();
    cmd = new OdbcCommand("AddEmployee");
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = cnx;
    cmd.Parameters.Add(new OdbcParameter("EmployeeID", "99999"));
    cmd.Parameters.Add(new OdbcParameter("EmployeeGroup", "Sales"));
    cmd.Parameters.Add(new OdbcParameter("EmployeeName", "John
    Smith"));
    cmd.ExecuteNonQuery();
    }
    catch
    {
    throw;
    }
    finally
    {
    cnx.Dispose();
    }
    if (cmd != null)
    cmd.Dispose();
    }
    }

    However, it throws an exception:
    ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.31-community]
    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 'AddEmployee' at
    line 1

    Any idea?

    Thanks
     
    Alan T, Jul 20, 2010
    #1
    1. Advertising

  2. Alan T

    Alan T Guest

    Hi,

    I modified and get differnent error about it did not get my parameters:

    cnx = new OdbcConnection(GetConnectionString());
    cmd = new OdbcCommand("CALL AddEmployee");
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = cnx;
    cmd.Parameters.Add("EmployeeID", "99999"));
    cmd.Parameters.Add("EmployeeGroup", "Sales"));
    cmd.Parameters.Add("EmployeeName", "John Smith");
    cnx.Open();
    cmd.ExecuteNonQuery();


    The error now is:
    + $exception {"ERROR [HY000] [MySQL][ODBC 5.1
    Driver][mysqld-5.1.31-community]Incorrect number of arguments for PROCEDURE
    myCompany.AddEmployee; expected 3, got 0"} System.Exception
    {System.Data.Odbc.OdbcException}
     
    Alan T, Jul 20, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JL
    Replies:
    0
    Views:
    1,151
  2. Ravi
    Replies:
    6
    Views:
    1,414
    Suchandra Thapa
    Jul 21, 2003
  3. Replies:
    2
    Views:
    6,203
  4. washakie
    Replies:
    4
    Views:
    928
    washakie
    Jan 15, 2008
  5. Jeffrey H. Coffield
    Replies:
    1
    Views:
    1,865
Loading...

Share This Page