To all,
I've solved most of the problem now!
PS. hope this message helps those who met DBConcurrencyException like
my case!
1) I've linked up the DataSet and DataGrid by using SetDataBindings
method
2) I've added a button to handle all updates within the DataGrid
3) within that button's code, I've setup the required SqlCommand like
this
-
try
-
{
-
if (this.mADO_CommandUpdateDGCustomers == null)
-
{
-
this.mADO_CommandUpdateDGCustomers = new SqlCommand
-
("Update Customers set " +
-
"CompanyName=@companyName, ContactName=@contactName
-
where CustomerID=@customerID",
-
mADO_Connection);
-
-
oParam = new SqlParameter ("@companyName",
-
System.Data.SqlDbType.VarChar, 255, "CompanyName");
-
oParam.SourceVersion =
-
System.Data.DataRowVersion.Current;
-
mADO_CommandUpdateDGCustomers.Parameters.Add (oParam);
-
-
oParam = new SqlParameter ("@contactName",
-
System.Data.SqlDbType.VarChar, 255, "ContactName");
-
oParam.SourceVersion =
-
System.Data.DataRowVersion.Current;
-
mADO_CommandUpdateDGCustomers.Parameters.Add (oParam);
-
-
oParam = new SqlParameter ("@customerID",
-
System.Data.SqlDbType.VarChar, 255, "CustomerID");
-
oParam.SourceVersion =
-
System.Data.DataRowVersion.Original;
-
mADO_CommandUpdateDGCustomers.Parameters.Add (oParam);
-
-
this.mADO_Adapter.UpdateCommand =
-
mADO_CommandUpdateDGCustomers;
-
}
-
}
-
catch (Exception ex)
-
{
-
return false;
-
}
-
finally
-
{
-
oParam = null;
-
}
-
return true;
-
4) please note how I used the SourceVersion and SourceColumn to map the
columns's data with the DataSet's Table's structure (ie. column)
5) finally; apply mADO_Adapter.Update (DataSetName, "TableName");
6) if no exception pops up, you've done it! Check for the DB records if
they were updated or not!
From Jason (Kusanagihk)