private static void Datatabletosqlserver (DataTable dt)
{
String connectionString = GetConnectionString ();
using (SqlConnection destinationconnection =new SqlConnection (connectionString))
{
Destinationconnection.open ();
using (SqlBulkCopy bulkcopy =new SqlBulkCopy (destinationconnection))
{
Try
{
Bulkcopy.destinationtablename = "t_eiinformation";//table name of the table to be inserted
BULKCOPY.COLUMNMAPPINGS.ADD ("email", "email");//Map Field name DataTable column name, database corresponding column name
BulkCopy.ColumnMappings.Add ("Author", "Author");
BulkCopy.ColumnMappings.Add ("title", "title");
BULKCOPY.COLUMNMAPPINGS.ADD ("Type", "type");
BULKCOPY.COLUMNMAPPINGS.ADD ("Confname", "confname");
BULKCOPY.COLUMNMAPPINGS.ADD ("Language", "Language");
BULKCOPY.COLUMNMAPPINGS.ADD ("Publicationyear", "publicationyear");
BULKCOPY.COLUMNMAPPINGS.ADD ("Conferencelocation", "conferencelocation");
Bulkcopy.writetoserver (DT);
}
catch (Exception ex)
{
Console.WriteLine (ex. Message);
}
Finally
{
Close the SqlDataReader. The SqlBulkCopy
object is automatically closed at the end
of the using block.
}
}
}
}
BULK INSERT Data C # sqlbulkcopy using