使用DataAdapter插入记录

时间:2011-07-17 21:24:44

标签: c# ado.net

DatasetTableAdapters.CustomerDataAdapter customerData = new DatasetTableAdapters.CustomerDataAdapter();

customerData.insertQuery("Value1", "Value");

记录未插入数据库为什么?我正在使用数据集设计器。

2 个答案:

答案 0 :(得分:0)

请尝试在表适配器上使用.Insert方法。

http://msdn.microsoft.com/en-us/library/ms233812(v=vs.80).aspx

答案 1 :(得分:0)

尝试这样的事情吗?

    DatasetTableAdapters.CustomerDataAdapter customerData = new DatasetTableAdapters.CustomerDataAdapter();

    //make instance of the applicable customerDataTable here

    customerData.Fill(customerDataTable);
    customerDataTable.Rows.Add("Value1", "Value");//<-you could also add the values directly to your dataset here instead of the datatable

    customerData.Update(customerDataTable);

我在winforms应用程序中使用此方法。也许你可以根据自己的需要编辑它?

相关问题