Hi guys. I'm new at your forum but I really need your help!
I'm working with DataGridView and put Update() method of my TableAdapter in the RowLeave event of my DGV. So when I add a new row it works perfectly but when i try to update some other row created before it gives me an error like this (translated from italian):
Update requires a valid UpdateCommand when a DataRow collection is passed through this method
I just use this construction:
this
.ticketsTableAdapter.Update(this.customersDBDataSet.Tickets);Can someone help me Maybe somebody knows another WORKING method to update DataGridView content. Thanks a lot. Looking forward to your suggestions :)

DataGridView Update Error
Go4More
Hi,
DataAdapter.Update method calls its Updatecommand, so you must implement the DataAdapter.UpdateCommand before using Update method.
Assuming you meant sqldataadapter, see: http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx
Thanks
ahmedilyas
Hi and thanks again! I just solved my problem. At last i decided to try to add the Primary Key and now it works perfectly! But now i have another LITTLE problem. I have to change BackgroundColor of some cells of DGV CheckBoxColumns (depending on its state - Checked or not). Firstly i had to change the color only to the cells of the only one column using this procedure:
if (e.ColumnIndex > -1)//i added this because sometimes it gave me ColumnIndex=-1 and i still don't know why
And till here it worked pretty good but then i had to add the same functionality also to another column and so i have just duplicated my code changing only column name:{
if (TicketsDataGridView.Columns[e.ColumnIndex].Name == statoTicketDataGridViewCheckBoxColumn.Name)
{
if (e.Value != null)
{
if (e.RowIndex < TicketsDataGridView.Rows.Count - 1)//except the last row - the new one
{
if ((bool)e.Value == false)
{
e.CellStyle.BackColor = Color.Red;
}
}
}
}
if (TicketsDataGridView.Columns[e.ColumnIndex].Name == esitoDataGridViewCheckBoxColumn.Name)
{
if (e.Value != null)
{
if (e.RowIndex < TicketsDataGridView.Rows.Count - 1)
{
if ((bool)e.Value == false)//CAST ERROR HERE - e.Value seems to be null
{
e.CellStyle.BackColor = Color.PapayaWhip;
}
else
{
e.CellStyle.BackColor = Color.LightGreen;
}
}
}
}
else if (e.ColumnIndex > -1)
{
if (TicketsDataGridView.Columns[e.ColumnIndex].Name == statoTicketDataGridViewCheckBoxColumn.Name)
{
if (e.Value != null)
{
if (e.RowIndex < TicketsDataGridView.Rows.Count - 1)
{
if ((bool)e.Value == false)
{
e.CellStyle.BackColor = Color.Red;
}
}
}
}
}
And now when i add a new row(so my new row becomes in edit mode and it's no more the last one) it gives me an error (in red) and i don't know what to do. It's strange because the other fit of code still works. Some suggestions Please!:)Greetings from Italy!
sofakng
CellFormatting event of my DataGridView. Thnx.
Veo
Hi,
Sorry for the delay replying.
Some code seem to be redundant.
If you want to change the color of the checked cell.
Here is sample code:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name != "CheckBoxColumn")
return;
if (e.Value != null)
if ((bool)e.Value)
e.CellStyle.BackColor = Color.Red;
}
And for more information about cell formatting event, see: http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting.aspx
Thank you
JSR2005
Jiajia
Woody_In_Sheffield
What type of e what event you use
Thanks
Hearty81
Yuvaraj
Hi,
Since you miss the PK in the database, if the connection didnt change and the catalog didnt change, there are not "much work" to do.
What is your problem
Thanks.