Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi
c#

I have dropped a data grid on a windows form and it displays the data from my table Ok. However, when I edit a

row and click save I then the message "Update requires a valid UpdateCommand when passed DataRow collection

with modified rows."

This is my table:

SQL
CREATE TABLE [dbo].[Orders](
	[OrderNumber] [int] IDENTITY(1,1)PRIMARY KEY,
	[insertday] [int] NOT NULL,
	[Details] [char](40) NULL,
	[Description] [char](40) NULL,
	[debit] [tinyint] NULL,
	[virtual] [tinyint] NULL,
	[CreditAccountNumber] [int] NULL,
	[DebitAccountNumber] [int] NULL,
	[Startdate] [datetime] NULL,
	[FirstAmount] [decimal](5, 2) NULL,
	[Amount] [decimal](5, 2) NULL,
	[totalpayments] [int] NOT NULL,
	[remainingpayments] [int] NOT NULL,
	[autoinsert] [tinyint] NULL,
) ON [PRIMARY]


Could someone tell me what the fix is here please?

1. WHERE do I set the update statement?
2. What does would update statement look like in this case?
Posted
Updated 22-Mar-15 4:08am
v2
Comments
Kornfeld Eliyahu Peter 22-Mar-15 10:09am    
The message you got related to your C# code and not to the SQL table structure...
Please show your relevant code...
KevinBadger 22-Mar-15 16:20pm    
See my comment

I am catching the error and putting up a message.

I didn't write the code, just like I didn't write code to populate mu grid and that works OK.

I don't understand why the update SQL was not defaulted to the correct thing?

But, as I say, I am new to this.
Dave Kreskowiak 22-Mar-15 11:22am    
Without seeing your C# code that throws this error it's impossible to help you.
KevinBadger 22-Mar-15 16:17pm    
Well, this is all a bit new to me
I didn't write the code for update, I dropted the grid onto the form:

private void ordersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try
{
this.Validate();
this.ordersBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.santanderDataSet);
}
catch (System.Exception ex)
{
MessageBox.Show(string.Format("Update failed ({0})", ex.Message));
}
}

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