0

Datatable在我的 C# 程序中有一个我想INSERT从 SQL Server 中的临时表中获取行。该dataAdapter.FILL()方法覆盖整个数据表。我需要保留DataTable临时表中的记录并将临时表中存在的记录添加回我的DataTable.

我没有看到 DA 方法,它们似乎都回到了 SQL Server 表,除了 FILL。这可能吗?

4

2 回答 2

2

合并你的数据表怎么样

DataTable dttemp = new DataTable();

dataAdapter.Fill(dtTemp);

originaldatatable.Merge(dtTemp);
于 2012-07-06T19:19:05.137 回答
0
// Now, open a database connection using the Microsoft.Jet.OLEDB provider.
// The "using" statement ensures that the connection is closed no matter what.
using (var connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data      source=Northwind.mdb"))
{
    connection.Open();

// Create an OleDbDataAdapter and provide it with an INSERT command.
var adapter = new OleDbDataAdapter();
adapter.InsertCommand = new OleDbCommand("INSERT INTO Shippers (CompanyName, Phone) VALUES (@CompanyName , @Phone)", connection);
adapter.InsertCommand.Parameters.Add("CompanyName", OleDbType.VarChar, 40, "CompanyName");
adapter.InsertCommand.Parameters.Add("Phone", OleDbType.VarChar, 24, "Phone");

adapter.Update(data);
}    
于 2012-07-06T19:19:24.393 回答