I have an ASP.NET project connecting to a database. A web page sends a query to the database. More than one, as a matter of fact, it reads from database successfully.
On click of a submit button I send an UPDATE query to the SQL Server (2008).
I work with C#, sending the UPDATE query to the server with a SqlCommand object initialized as such:
Edit: Added variables to query.
string strQuery = "UPDATE [tbl] SET [f1]='" + stringValue + "', [f2]='" + (boolValue?"1":"0") + "' WHERE [id]=" + intId.ToString() + ";";
SqlCommand cmd = new SqlCommand(strQuery, connectionObject);
int QueryResult = cmd.ExecuteNonQuery();
QueryResult ends up 0, and, of course, no change done. Copy-Paste to SSMS – I get 1 row(s) affected and the data changes.
Connection works fine – when I use this to check the work on the DB – the query has been executed. (It looks something like (@1 varchar(8000), @2 varchar(8000), @3 tinyInt) UPDATE [tbl] SET [f1]=@1, [f2]=@2 WHERE [id]=@3;).
Any idea what’s going on – appreciated.
Thank you!
The most likely thing is that the
WHERE [id]=" + intId.ToString()isn’t finding the row to be updated.Either this is because:
If you put a breakpoint on the line after the
strQueryassignment see what it contains, and maybe post its contents back into your question.