2
Answers

Adding parameters to ODBC MySQL queries

Ben Gannaway

Ben Gannaway

15y
4.6k
1
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)