代码如下:调试报错:其他信息: 当传递具有已修改行的 DataRow 集合时,更新要求有效的 UpdateCommand。,我不知道怎么改,请各位大哥指点一下,我那里错了.
string strComm ="select * from kh_org where login_name='"+account+"'and ORG_TYPE = '3'";
OleDbCommand cmdCommand = new OleDbCommand(strComm,m_connConnection);
OleDbDataAdapter adAdapter = new OleDbDataAdapter();
adAdapter.SelectCommand = new OleDbCommand(strComm, m_connConnection);
DataSet ds = new DataSet();
adAdapter.Fill(ds,"kh_org");
DataRow[] dr=ds.Tables["KH_ORG"].Select("password='"+oldpassword+"'");
try
{ if (dr.Length !=0)
{
dr[0]["password"]= newpassword;
adAdapter.Update(ds,"KH_ORG");
m_connConnection.Close();
return true;
}
else
{
MessageBox.Show("与原来数据不一致!");
return false;
}
}
catch (OleDbException)
{
MessageBox.Show("与原来数据不一致!");
return false;
}
string strComm ="select * from kh_org where login_name='"+account+"'and ORG_TYPE = '3'";
OleDbCommand cmdCommand = new OleDbCommand(strComm,m_connConnection);
OleDbDataAdapter adAdapter = new OleDbDataAdapter();
adAdapter.SelectCommand = new OleDbCommand(strComm, m_connConnection);
DataSet ds = new DataSet();
adAdapter.Fill(ds,"kh_org");
DataRow[] dr=ds.Tables["KH_ORG"].Select("password='"+oldpassword+"'");
try
{ if (dr.Length !=0)
{
dr[0]["password"]= newpassword;
adAdapter.Update(ds,"KH_ORG");
m_connConnection.Close();
return true;
}
else
{
MessageBox.Show("与原来数据不一致!");
return false;
}
}
catch (OleDbException)
{
MessageBox.Show("与原来数据不一致!");
return false;
}
当你要更新数据时,请指定UpdateCommand,或InsertCommand,或DeleteCommand,这三种命令分别执行更新,修改,删除操作
问题是解决了,但是出现新的问题,调试的时候总是跳到catch (OleDbException),显示错误是:update语法错误,我晕死,各位大哥在看看啊
下添加
OleDbCommandBuilder custCB = new OleDbCommandBuilder(adAdapter);
试的时候总是跳到catch (OleDbException),显示错误是:update语法错误,我晕死,各位大哥在看看啊