Ben Gannaway

Ben Gannaway

  • NA
  • 12
  • 0

Adding parameters to ODBC MySQL queries

Nov 5 2009 6:11 AM
I have just ported my database connection over to MySQL using ODBC.  However, none of my parameters are being substituted out into the query and are appearing in my database as null. 
I am adding parameters to my query as shown below:
                OdbcCommand myCommand = myConnection.getCommand("INSERT INTO entries(text, name, screen_name, user_id, posi_score)values(@txt, @nm, @scrNm, @uid, @posi_score)");                
myCommand.Parameters.AddWithValue("@txt", txt);
myCommand.Parameters.AddWithValue("@nm", nm);
myCommand.Parameters.AddWithValue("@scrNm", scrNm);
myCommand.Parameters.AddWithValue("@uid", uid);
myCommand.Parameters.AddWithValue("@posi_score", posiScore);
myConnection.openConnection();
try
{
myCommand.ExecuteNonQuery();
}
catch (Exception e)
{
Console.Write("Insert failed on entries "+e.Message);
}
Is there a different method for adding command parameters for ODBC connections?

Answers (2)