adpater.update()问题,insert没问题,update就报错 affected 0 of the expected 1 records
窗口只有1个datagridview和一个button1,datagidview编辑数据,button1确定更新
当插入新数据的时候,可以成功插入,当编辑现有数据update的时候,一点更新就报错。提示:“Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.”
我根本不知道错在哪里了。希望指点
代码如下
当插入新数据的时候,可以成功插入,当编辑现有数据update的时候,一点更新就报错。提示:“Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.”
我根本不知道错在哪里了。希望指点
代码如下
public partial class FormAccess : Form
{
OleDbConnection connect = new OleDbConnection(@";Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ESDB.accdb");
DataTable dt=new DataTable ();
OleDbDataAdapter adapter;
public FormAccess()
{
InitializeComponent();
}
private void FormAccess_Load(object sender, EventArgs e)
{
connect.Open();
adapter = new OleDbDataAdapter();
string selectText = "select * from factory";
DbCommand selectCommand = new OleDbCommand(selectText, connect);
adapter.SelectCommand =(OleDbCommand ) selectCommand;
adapter.Fill(dt);
dataGridView1.DataSource = dt;
string insertText="insert into factory (factoryCode,factoryName,description) values(@factoryCode,@factoryName,@description)";
string updateText = "update factory set factoryName=@factoryname,description=@description where factoryCode=@factoryCode";
OleDbCommand insertCommand = new OleDbCommand(insertText, connect);
insertCommand.Parameters.Add("@factoryCode", OleDbType.VarWChar, 0, "factoryCode");
insertCommand.Parameters.Add("@factoryName", OleDbType.VarWChar, 0, "factoryName");
insertCommand.Parameters.Add("@description", OleDbType.VarWChar, 0, "description");
OleDbCommand updateCommand = new OleDbCommand(updateText, connect);
updateCommand.Parameters.Add("@factoryCode", OleDbType.VarWChar, 0, "factoryCode");
updateCommand.Parameters.Add("@factoryName", OleDbType.VarWChar, 0, "factoryName");
updateCommand.Parameters.Add("@description", OleDbType.VarWChar, 0, "description");
adapter.UpdateCommand = (OleDbCommand)updateCommand;
adapter.InsertCommand = (OleDbCommand)insertCommand;
}
private void button1_Click(object sender, EventArgs e)
{
adapter.Update(dt);
}
...全文
相关推荐
实验13:insert update delete注入
基于insert update delete的注入利用 一、insert/update注入 打开Pikachu中的insert/update注入 点击注册界面 首先测试注入点,通常我们用”单引号“来测试,在必选项上分别输入”单引号“ 因此,我们可以利用报错获取信息 用户名输入nihao’ or updatexml(1,concat(0x7e,database()),0) or ’ 密码随意输入,...
电子商务案例分析(第七版)课程标准+课件+教案+试卷及答案
电子商务案例分析(第七版)课程标准+课件+教案+试卷及答案
政府科技管理者在审批科技成果转化项目时,如何高效核实技术成果的知识产权归属?.docx
政府科技管理者在审批科技成果转化项目时,如何高效核实技术成果的知识产权归属?
技术经理人上岗后成长慢?AI工具打造从上手到出活的全链路支撑.docx
技术经理人上岗后成长慢?AI工具打造从上手到出活的全链路支撑
数媒大赛ai工具使用word说明
数媒大赛ai工具使用word说明


