C
C#2y ago
Misae

✅ ASP.NET OLEDB ExecuteNonQuery UpdateSyntax Error

I made this
OleDbCommand sqlcommand2 = new OleDbCommand();
string update = "UPDATE [TBL-Users] SET username = '" + Change2UsernameTextBoxID.Text +"'"+ "," + " password = '" + Change2PasswordTextBoxID.Text + "' WHERE username = '" + ChangeUpdateUserNameTextBoxID.Text + "' AND password = '" + ChangeUpdatePasswordTextboxID.Text + "'";
sqlcommand2 = new OleDbCommand(update,connection);
sqlcommand2.ExecuteNonQuery();

connection.Close();
Response.Write("<script>alert('Update Successful');</script>");
OleDbCommand sqlcommand2 = new OleDbCommand();
string update = "UPDATE [TBL-Users] SET username = '" + Change2UsernameTextBoxID.Text +"'"+ "," + " password = '" + Change2PasswordTextBoxID.Text + "' WHERE username = '" + ChangeUpdateUserNameTextBoxID.Text + "' AND password = '" + ChangeUpdatePasswordTextboxID.Text + "'";
sqlcommand2 = new OleDbCommand(update,connection);
sqlcommand2.ExecuteNonQuery();

connection.Close();
Response.Write("<script>alert('Update Successful');</script>");
But it always says that I made a syntax error on my update, but when I use it on SQL query in Microsoft Access, it works just fine on the same table. I would get if it actually just doesn't work and I fucked up, but it works on Access so I'm super confused. Any help would be greatly appreciated
4 Replies
Angius
Angius2y ago
Use parametrized queries
Misae
MisaeOP2y ago
Sorry, as of now I'm not familiar of the method, I've been searching and I can't find results on google
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server