Bulk insert into MSSQL Server after mapping datatable column to
Sqltable Column.
public
void getdata_mstoms(string[,]
columlist,string D_Conn,
string D_Table,DataTable dt)
{
using
(SqlConnection cn = new SqlConnection(D_Conn))
{
cn.Open();
using
(SqlBulkCopy copy = new SqlBulkCopy(cn))
{
for
(int i = 0; i < columlist.Length / 2; i++)
{
if
(columlist[i, 1] != null)
{
copy.ColumnMappings.Add(columlist[i, 0].ToString(), columlist[i, 1].ToString());
}
}
copy.DestinationTableName =
D_Table;
copy.WriteToServer(dt);
}
}
}
where
columnlist =[sqltablefield,datatablefield] is a 2-d string array where mapping
is given at runtime.