jannas szas
jannas szas

Reputation: 25

Cannot Call Mysql store procedure on C#

I'm using mysql 5.6 version and C# I created stored procedure call PWITEMS().

delimiter //
create procedure PWITEMS() 
begin 
select Jw_ItemName,Jw_ItemID FROM pawning.jewelry_items;
end;//
delimiter ;

When I call that procedure it gives the error:

ERROR [42000] [MySQL][ODBC 5.3(w) Driver][mysqld-5.6.26-log]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 'NewPWITEMS' at line 1

My C# code is here:

OdbcDataReader dr;
OdbcConnection cnn = new OdbcConnection(Form1.dbconn.str);
OdbcCommand cmd = new OdbcCommand("NewPWITEMS", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cnn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
    cmbJewType.Items.Add(dr[0].ToString());
}

dr.Dispose();
cnn.Close();
cmd.Dispose();

Upvotes: 0

Views: 157

Answers (1)

PaulF
PaulF

Reputation: 6783

The MySQL the command would be

CALL PWITEMS

(I note your definition was for PWITEMS, not NewPWITEMS)

See comment below - the ODBC docs specify the correct way is to surround the call with braces : http://vieka.com/esqldoc/esqlref/htm/odbcprocedure_calls.htm

Upvotes: 1

Related Questions