用DataAdpter
这里有个示例:http://www.cnblogs.com/lizhang0101/archive/2008/11/10/1800597.html
ORACLE下只要把命名空间改一下就OK了
DataAdpter的结构也可以自己构建的
@artwl: 您好 我是初学 不是太懂
可不可以帮我看看代码
DbProviderFactory dbf=DbProviderFactories.GetFactory("System.Data.OracleClient");
string strSql = "select * from mcemployeeinfogs where rownum=1";
DbCommand cmd2 = db1.GetSqlStringCommond(strSql);
DbDataAdapter ddb = dbf.CreateDataAdapter();
ddb.SelectCommand = cmd2;
DataSet dsd = new DataSet();
ddb.Fill(dsd);
DbCommandBuilder dcb = dbf.CreateCommandBuilder();
dcb.DataAdapter = ddb;
ddb.InsertCommand = dcb.GetDeleteCommand();
ddb.UpdateCommand = dcb.GetUpdateCommand();
ddb.DeleteCommand = dcb.GetDeleteCommand();
dsd = dst;
ddb.Update(dsd,"mcemployeeinfogs");
@silverlight4: 运行后有什么问题吗?
@artwl: 运行没有错误 但是DataSet更新了,数据库不更新
@silverlight4: 最后还有这个,别掉了:ds.AcceptChanges();
@artwl: 恩 我写上了 还是不行啊 麻烦您了
@silverlight4: 你这段代码中并没有对数据进行修改啊,当然看不到效果啦
@artwl: 可是我吧源数据(dst)直接赋值给目的数据集(dsd)了啊
@silverlight4: 解决了 谢谢您
ddb.InsertCommand = dcb.GetDeleteCommand();
改为
ddb.InsertCommand = dcb.GetInsertCommand();
@silverlight4: 不客气,记得结帖哦^^
用“DataAdpter”设配器啊。
您也帮忙看看吧 不更新数据库,
DbProviderFactory dbf=DbProviderFactories.GetFactory("System.Data.OracleClient");
string strSql = "select * from mcemployeeinfogs where rownum=1";
DbCommand cmd2 = db1.GetSqlStringCommond(strSql);
DbDataAdapter ddb = dbf.CreateDataAdapter();
ddb.SelectCommand = cmd2;
DataSet dsd = new DataSet();
ddb.Fill(dsd);
DbCommandBuilder dcb = dbf.CreateCommandBuilder();
dcb.DataAdapter = ddb;
ddb.InsertCommand = dcb.GetDeleteCommand();
ddb.UpdateCommand = dcb.GetUpdateCommand();
ddb.DeleteCommand = dcb.GetDeleteCommand();
dsd = dst;
ddb.Update(dsd,"mcemployeeinfogs");