Hi all, having a very frustrating problem. When inserting through stored procedure using ODBC I am getting an error saying that I have an error in my sql near the procedure name?
The procedure works fine from MySql so guess the fault is in my code somewhere? I have supplied both for completeness.
An help appreciated.
C#
MySql Procedure
Note: I have tried the params with an @ or without any
Age is a consequence of experience
The procedure works fine from MySql so guess the fault is in my code somewhere? I have supplied both for completeness.
An help appreciated.
C#
Code:
public static int TestInsertProduct( Product product )
{
int rec = 0;
OdbcConnection con = ArtizanConnection.GetAClosedConnection( );
OdbcCommand myCommand = new OdbcCommand( );
myCommand.CommandText = "ProductInsertNewTest";
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Connection = con;
myCommand.Parameters.AddWithValue( "?pName", product.Name ) ;
myCommand.Parameters["?pName"].Direction = ParameterDirection.Input;
myCommand.Parameters.AddWithValue("?pReOrderLevel", product.ReOrderLevel );
myCommand.Parameters["?pReOrderLevel"].Direction = ParameterDirection.Input;
con.Open( );
try
{
myCommand.ExecuteNonQuery( );
}
catch ( OdbcException ex )
{
Console.WriteLine( ex.Message );
}
catch(Exception ex)
{
Console.WriteLine( ex.Message );
}
finally { con.Close( ); }
return rec;
}
MySql Procedure
Code:
DELIMITER $$
DROP PROCEDURE IF EXISTS artizan.ProductInsertNewTest $$
CREATE PROCEDURE artizan.ProductInsertNewTest(in pName varchar(50), in pReOrderLevel int(11))
BEGIN
INSERT INTO artizan.Product (Name, ReOrderLevel )
VALUES ( pName, pReOrderLevel);
SELECT LAST_INSERT_ID();
END $$
DELIMITER ;
Note: I have tried the params with an @ or without any
Age is a consequence of experience