/// <summary>
/// 将datatable插入数据库
/// </summary>
/// <param name="table1"></param>
public void InsertTable(DataTable table1)
{
//table1 与 数据库的目标表 列名要一样
SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(Repository.DataContext.ConnectionString);
sqlBulkCopy.DestinationTableName = "Fore_Results";
if (table1 != null && table1.Rows.Count != 0)
{
for (int i = 0; i < table1.Columns.Count; i++)
{
//列映射定义数据源中的列和目标表中的列之间的关系
sqlBulkCopy.ColumnMappings.Add(table1.Columns[i].ColumnName, table1.Columns[i].ColumnName);
}
sqlBulkCopy.WriteToServer(table1);
}
sqlBulkCopy.Close();
}