解决并发冲突 执行用于在 Try...Catch 块中更新数据库的命令。
如果引发异常,则检查 Catch 语句的 Row 属性,以确定导致冲突的原因。
根据您的应用程序业务规则添加代码来解决错误。
try
{
SqlDataAdapter1.Update(myDataset);
}
catch (DBConcurrencyException ex)
{
string customErrorMessage;
customErrorMessage = "Concurrency violation\n";
customErrorMessage += ex.Row[0].ToString();
// Replace the above code with appropriate business logic
// to resolve the concurrency violation.
}
如果引发异常,则检查 Catch 语句的 Row 属性,以确定导致冲突的原因。
根据您的应用程序业务规则添加代码来解决错误。
try
{
SqlDataAdapter1.Update(myDataset);
}
catch (DBConcurrencyException ex)
{
string customErrorMessage;
customErrorMessage = "Concurrency violation\n";
customErrorMessage += ex.Row[0].ToString();
// Replace the above code with appropriate business logic
// to resolve the concurrency violation.
}
解决方案 »
- 关于listview和datagridview的问题..
- 谁给我讲下IEnumerator怎么用啊.
- 如何通过C#修改计算机系统时间?急急!
- 请教:c#问题
- 请高手指点条路
- 关于RadioButtonList的问题,谁能帮忙解决一下?
- 高分求NHibernate联合查询解决方法,不够开新贴加分!!!
- 关于文件读写的问题
- 如何将DataGrid的某一列与一个Combox结合?
- 请问XML中像下面rl:entry带命名空间的节点怎么反序列化,多谢
- 打开收藏夹时网页自动收缩是用什么方法?
- 我把在别的机器上修改过的新版本项目文件覆盖本机器上的旧版本的项目文件,在vs.net中,打开解决方案时,出现“无法与服务器建立连接”,
这个方法可以试试,因为我在做程序的时候也碰你上面的问题。
acceptchanges()之后可以的。
还有如果我更新cDI_FileNameOld = @cDI_FileNameOld这个字段。无论我输入任何字符串,数据库存的都是0
为什么
我按照你的方法做了,现在报错是这样的。
System.Data.OleDb.OleDbException: UPDATE 语句的语法错误。Line 385: try
Line 386: {
Line 387: dsCommand.Update(upLoadDV,UpLoadDVInfo_TABLE);
Line 388: }
Line 389: catch (DBConcurrencyException ex)
{
// For bound columns, the edited value is stored in a TextBox.
// The TextBox is the 0th element in the column's cell.
TextBox oldFileNameText = (TextBox)e.Item.Cells[2].Controls[0];
TextBox hbFileNameText = (TextBox)e.Item.Cells[4].Controls[0];
String FilmName= e.Item.Cells[1].Text;
String oldFileName = oldFileNameText.Text;
String hbFileName = hbFileNameText.Text;
bool result;
DataRow checkDataRow = checkDataTable.Rows[e.Item.ItemIndex];
checkDataRow[upLoadDVData.cDI_FileNameOld_FIELD]=oldFileName;
checkDataRow[upLoadDVData.cDI_ImageFileName_FIELD]=hbFileName;
// Label1.Text=checkDataRow[upLoadDVData.iDI_ID_FIELD].ToString();
result=upLoadDVData.UpdateUpLoadDV(checkDataSet);
// With a database, use an update command to update the data. Because
// the data source in this example is an in-memory DataTable, delete the
// old row and replace it with a new one.
if(result)
{
checkDataGrid.EditItemIndex = -1;
BindGrid();
}
这是datagrid的update事件