Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inser to MySql Stored proc error

Status
Not open for further replies.

litton1

Technical User
Apr 21, 2005
584
GB
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#
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
 
Solved:
Moved to the Mysql.Data.Client and it just worked

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top