将通用列表上载到数据库
本文关键字:数据库 上载 列表 | 更新日期: 2023-09-27 18:35:38
如何将遗传List<T>
上传到SQL数据库。
两种方式都做到了,我的钱在数据表上。
见 http://msdn.microsoft.com/en-us/library/ex21zs8x%28v=vs.110%29.aspx
// Create a table with some rows.
DataTable newProducts = MakeTable();
// Create the SqlBulkCopy object.
// Note that the column positions in the source DataTable
// match the column positions in the destination table so
// there is no need to map columns.
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
{
bulkCopy.DestinationTableName =
"dbo.BulkCopyDemoMatchingColumns";
try
{
// Write from the source to the destination.
bulkCopy.WriteToServer(newProducts);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}