C# DataSet更新不了数据库

来源:百度知道 编辑:UC知道 时间:2024/05/22 11:48:16
oledap.Fill(ds, "dfdf");
DataRow []drCurrent = ds.Tables["dfdf"].Select("sd='asdfasf'");
if (drCurrent.Length == 0) MessageBox.Show("0000");
else
{
drCurrent[0].Delete();
ds.Tables["dfdf"].AcceptChanges();

}
MessageBox.Show(oledap.Update(ds, "dfdf").ToString());

//结果:0 //即更新0行..
我的测试:
ds,未删除行时:count=3
执行删除count=2
但是执行update时.返回0?????为什么,,??我找了两天了...
用一个oledap.DeleteCommand的对象可以删除,不过不是用DataSet更新的,而且还要新定义一个Connection对象,,我试过的,可以删除,
但我还是想问DataSet更新的方法,,,,谁帮我看看..谢谢
测试过:
drCurrent.Length =1

灵雨飘零 朋友,,谢谢您的回答,,
想问下.
OleDbCommandBuilder 申请了,有什么用

这是链接Access数据库的一个例子,希望对你有用!

public class DBCon
{
string strCon;
string strPath;
public DBCon()
{
strPath = Application.StartupPath + "\\Drawing.mdb";
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + strPath;

}
public DBCon(string dbCon)
{
this.strCon = dbCon;
}

//查询语句
public DataSet Query(string strSql)
{
DataSet ds = new DataSet();
using(OleDbConnection oleCon=new OleDbConnection(strCon))
{
OleDbDataAdapter oleDap = new OleDbDataAdapter(strSql,strCon);
oleDap.Fill(ds);
}
return ds;
}

public object Scale(string strSql)
{
object obj=&quo