I am having a table as follows
Info (Srno int, InfoName varchar(20), InfoDetails varchar(40)) Srno as primary key
I show the records of this table in a grid using
da = new SqlDataAdapter(string.Format("select * from {0}", TableName), con);
da.Fill(dt);
SqlCommandBuilder cmdbldBINDASS = new SqlCommandBuilder(da);
dgv.DataSource = dt;
dt.PrimaryKey = new DataColumn[] { dt.Columns[m_StrColumnsName[(int)COLUMN_NAMES.SRNO]] };
dt.AcceptChanges();
dgv.Sort(dgv.Columns[m_StrColumnsName[(int)COLUMN_NAMES.SRNO]], ListSortDirection.Ascending);
Now whenever I deletes a record, I alse want to update the srno of all the records. Ie.
if i am having following records
Srno InfoName InfoDetails
1 ABC ghshd
2 XYZ fkjkfj
3 FGt wgwwiii
4 hjk dkwldiw
and I delete record of srno 2 then I want to update the rest of the records srno. ie
Srno InfoName InfoDetails
1 ABC ghshd
2 FGt wgwwiii
3 hjk dkwldiw
I write following command to delete row from grid and data base
dgv.Rows.Remove(row);
da.Update(dt);
and following command to update rest of the sr numbers
foreach (DataGridViewRow item in abc)
{
if (!item.IsNewRow)
{
item.Cells[m_StrColumnsName[(int)COLUMN_NAMES.SRNO]].Value = item.Index +1;
}
}
and calls to update it in data base
da.Update(dt) // but this command is giving me concurrency violation exception
please suggest what I should do for this?? I just want to delete a primary row value, and update rest of the records.