0

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.

2
  • Could be a probem with the timeformat. There are many formats possible. Watch here: msdn.microsoft.com/en-us/library/ms186724.aspx Commented Sep 18, 2015 at 16:41
  • 2
    Is it really called "shedulling" which is spelled incorrectly? What error are you getting? Also you need to read up on SQL injection prevention, this application is very susceptible to a SQL injection attack. Commented Sep 18, 2015 at 16:42

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.