Click here to Skip to main content
15,936,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagridview in form1, the user selects a row and relevant details are sent to the correlating textboxes in form2. from here the user clicks a button which should update a cell in the row selected (in the database) and change it to 'In production'(which is the orderstatus textbox.

I want to be able to update a row which correlates to the customer ID, which is a primary key in the database... currently the software updates everything within the database table ...

I have tried to debug it i cannot see the error

MAcon.Open();
OleDbCommand cm = new OleDbCommand("UPDATE [Customer Orders] SET [Order Status]=@OrderStatus WHERE [CustomerID]=@CustomerID", MAcon);
cm.Parameters.AddWithValue("@OrderStatus", textBox4.Text);
cm.Parameters.AddWithValue("@CustomerID", CustID.Text);
cm.ExecuteNonQuery();
MAcon.Close();


What I have tried:

MAcon.Open();
OleDbCommand cm = new OleDbCommand("UPDATE [Customer Orders] SET [Order Status]=@OrderStatus WHERE [CustomerID]=@CustomerID", MAcon);
cm.Parameters.AddWithValue("@OrderStatus", textBox4.Text);
cm.Parameters.AddWithValue("@CustomerID", CustID.Text);
cm.ExecuteNonQuery();
MAcon.Close();
Posted
Updated 15-May-18 13:11pm
v2
Comments
j snooze 15-May-18 17:43pm    
I do not see an error posted. What seems to be the issue? are you saying the above code is updating every record in the table instead of just the customer id you are sending?
Member 13765884 15-May-18 18:00pm    
It updates all the other rows also

I have solved the issue,
[CustomerID]
should be
[Customer ID]
instead
 
Share this answer
 
SQL doesn't work that way. It just doesn't. Unless they all have the same id, or different SQL is running, this just won't happen.

Have you considered using Entity Framework? This string mashing SQL is awful
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900