The data is written to the DataTable batch SQL SERVER table

///


/// the data written to the DataTable in bulk SQL SERVER table
///

/// the DataTable memory table
/// database connection string
/// database table
public static void DataTableToSqlServer (the DataTable dt, connectString String, String SqlserverTableName)
{
String the connectionString = connectString;
the using (the SqlConnection destinationConnection the SqlConnection new new = ())
{
destinationConnection.Open ();
the using (the SqlBulkCopy bulkcopy the SqlBulkCopy new new = (destinationConnection))
{
the try
{
bulkCopy.DestinationTableName = SqlserverTableName; // to insert a table name of the table
bulkCopy.BatchSize = dt.Rows.Count;
int Y = dt. Columns.Count; // number of columns in the table memory
bulkCopy.ColumnMappings.Add ( "FromSubinv", "FromSubinv "); // DataTable column name mapping field name, column name corresponding to the database
}
catch (Exception ex)
{
throw ex;
}
}
}
}

Guess you like

Origin www.cnblogs.com/zhujie-com/p/12310217.html