Reputation: 43
I am creating a Windows Forms application and now at certain point I need to make a database connection, I have inserted the values to database easily, but now its not updating my data, I am using following query for this purpose:
MySqlCommand sda = new MySqlCommand(@"Update shedulling.tablelayout1 set date = '"
+ date + "',line = " + line + ",col1 = '" + first_textbox.text + "', col2 = '"
+ sec_textbox.text + "',col3_textbox.text = '" + thi_textbox.text
+ "',col4_textbox.text = '" + four + "' where date = '" + date + "' AND line = '"
+ line.ToString() + "' ", conn);
conn
is a connection string which is written fine, and date
and line
are string and integer values send as an argument to this function.
Upvotes: 0
Views: 83
Reputation: 39956
You have missed single quotes in line
part. Change it like this line = '" + line + "'
.
Also there is one more notable thing in your code: you are trying to find the record in the table that is not exist yet in where
clause where date = '" + date + "' AND line = '" + line.ToString() + "'
note in this line date
and line
are the new values not old values so no rows affected in the update query. You should use old values of date
and line
in the where
clause.
Also you should always use parameterized queries
. This kind of string concatenations are open for SQL Injection
.
Upvotes: 2
Reputation: 4005
Try debugging the code, there must be INSERT statement executing somewhere in your code.
UPDATE: If "line" is integer variable then you need to convert it into string. You have converted it after WHERE clause but not after SET clause.
You may want to post some more code to get exact answer.
Upvotes: 0