2011-07-17 62 views
0
DatasetTableAdapters.CustomerDataAdapter customerData = new DatasetTableAdapters.CustomerDataAdapter(); 

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

記錄未插入數據庫爲什麼?我正在使用數據集設計器。使用DataAdapter插入記錄

回答

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應用程序中使用此方法。也許你可以編輯它以適應您的需求?

+0

而不是.Update方法,你可以嘗試使用你的.insertQuery,看看是否也可以。但是因爲新行被添加到數據表中,所以更新會自動插入,因爲它不會編輯dataTable中的一行。 –