Adding parameters to ODBC MySQL queriesBGBen Gannaway17yAsked Nov 5, 2009, 1:11 AM ESTSolvedShareLinkedInXCopy linkSaveI 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:JavaCopy 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?
Adding parameters to ODBC MySQL queriesBGBen Gannaway17yAsked Nov 5, 2009, 1:11 AM ESTSolvedShareLinkedInXCopy linkSaveI 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:JavaCopy 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?
Kirtan PatelRank #292 · 8.6K reputation17y agoPosted Nov 5, 2009, 1:21 AM EST✓ Accepted answer0Friend if you are using My SQL Then Why dont you using MySQL Connector Which will better handle MySQL then Odbc Connection ..After installing my SQL Connector You will have New Name space System.Data.MySqlthen you can use all the Facilities better and you will easily handle this type of operation :)Download My SQL Connector from Here http://dev.mysql.com/downloads/connector/net/6.2.htmlif my answer helped you then check "Do you like this answer" check Box :)0
BGBen Gannaway12 reputation17y agoPosted Nov 5, 2009, 2:39 AM EST0That was a surprisingly quick solution. It seems ODBC connection doesn't support parameters. Thanks for the link0
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 5, 2009, 1:21 AM EST
After installing my SQL Connector You will have New Name space
System.Data.MySql
then you can use all the Facilities better and you will easily handle this type of operation :)
Download My SQL Connector from Here
http://dev.mysql.com/downloads/connector/net/6.2.html
if my answer helped you then check "Do you like this answer" check Box :)
Ben Gannaway12 reputationPosted Nov 5, 2009, 2:39 AM EST