Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > OdbcCommand exception - MySQL

Reply
Thread Tools

OdbcCommand exception - MySQL

 
 
Alan T
Guest
Posts: n/a
 
      07-20-2010
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


 
Reply With Quote
 
 
 
 
Alan T
Guest
Posts: n/a
 
      07-20-2010
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}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
"mysql.h: No such file or directory" when building MySQL-python francescomoi@europe.com Python 2 05-11-2005 03:12 PM
DBD:mysql doesn't read mysql option file /etc/my.cnf file JL Perl 0 01-28-2005 03:19 AM
"Pure Python" MySQL module like Net::MySQL Ravi Python 6 07-21-2003 06:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57