本文介绍了无法将DataTable更新为sql DataBase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public SomeMethod{
DataSet ds = new DataSet();
SqlCommand testCaseCommand = new SqlCommand(pTestCaseTableQueryString, SQLconnection);
this._testCaseDataAdapter = new SqlDataAdapter(testCaseCommand);
this._testCaseCommandBuilder = new SqlCommandBuilder(_testCaseDataAdapter);
//this._testCaseDataAdapter.Fill(testCaseDataTable);
this._testCaseDataAdapter.Fill(ds, "QualityCheckTestCaseTable");
this._testCaseDataAdapter.DeleteCommand = this._testCaseCommandBuilder.GetDeleteCommand(true);
this._testCaseDataAdapter.UpdateCommand = this._testCaseCommandBuilder.GetUpdateCommand(true);
this._testCaseDataAdapter.InsertCommand = this._testCaseCommandBuilder.GetInsertCommand(true);
this._testCaseSourceBindingSource = new BindingSource();
this._testCaseSourceBindingSource.DataSource = ds;
this._testCaseSourceBindingSource.DataMember = "QualityCheckTestCaseTable";
SqlCommand designerItemCommand = new SqlCommand(pDesignerItemQuertyString, SQLconnection);
this._designerItemDataAdapter = new SqlDataAdapter(designerItemCommand);
this._DesignerItemCommandBuilder = new SqlCommandBuilder(this._designerItemDataAdapter );
//this._designerItemDataAdapter.Fill(designerItemDataTable);
this._designerItemDataAdapter.Fill(ds,"AnticipationDesignerItemTable");
this._designerItemDataAdapter.DeleteCommand = this._DesignerItemCommandBuilder.GetDeleteCommand();
this._designerItemDataAdapter.UpdateCommand = this._DesignerItemCommandBuilder.GetUpdateCommand();
this._designerItemDataAdapter.InsertCommand = this._DesignerItemCommandBuilder.GetInsertCommand();
var relation = new DataRelation("TestCaseRelation", ds.Tables["QualityCheckTestCaseTable"].Columns["TestCaseID"],
ds.Tables["AnticipationDesignerItemTable"].Columns["RTestCaseID"]);
ds.Relations.Add(relation);
this._designerItemBindingSource = new BindingSource();
this._designerItemBindingSource.DataSource = this._testCaseSourceBindingSource;
this._designerItemBindingSource.DataMember = "TestCaseRelation";
}
public SaveTableToSQL()
{
this._testCaseDataAdapter.Update(QualityCheckTestCaseTabl);
this._designerItemDataAdapter.Update(AnticipationDesignerItemTable);
}
当我修改AnticipationDesignerItemTable时,它可以工作。但是当我修改QualityCheckTestCaseTable时,无需更改
tthanks
when i modify AnticipationDesignerItemTable, it can work. But when i modify QualityCheckTestCaseTable, have nothing to change
tthanks
推荐答案
这篇关于无法将DataTable更新为sql DataBase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!