Reputation: 5800
What is the error in the below code, and how do I pass [email protected]
and [email protected]
using forms?
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=new_db;" + "UID=root;" + "PASSWORD=password;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcCommand cmd = new OdbcCommand("UPDATE awm_create SET [email protected] WHERE [email protected]" , MyConnection);
MyConnection.Open();
cmd.ExecuteNonQuery();
Upvotes: 0
Views: 8968
Reputation: 14100
Try this:
OdbcCommand cmd = new OdbcCommand("UPDATE awm_create
SET referral_email='[email protected]' WHERE email='[email protected]'",
MyConnection);
If you need to parameterize that query, you can do something like:
OdbcCommand cmd = new OdbcCommand("UPDATE awm_create
SET referral_email=? WHERE email=?", MyConnection);
cmd.Parameters.Add("@referral_email", OdbcType.VarChar).Value = "[email protected]";
cmd.Parameters.Add("@email", OdbcType.VarChar).Value = "[email protected]";
Upvotes: 2
Reputation: 1234
My trick when faced with this type of error is to copy the SQL query from the code and execute it directly against the database using the database user interface. This way I ensure where the error lies. Yes you're missing the string delimiters and the query interface to MYSql would tell you that while the IDE interface only knows that there was an error.
If that step works then go up the chain to figure out what doesn't.
Upvotes: 1
Reputation: 360682
Your query has syntax errors:
UPDATE awm_create SET [email protected] WHERE [email protected]
there's no quotes around either email address. It should be
UPDATE awm_create SET referral_email='[email protected]' WHERE email='[email protected]'
^-- ^-- ^-- ^--
Upvotes: 1