// Get the DataTable
DataTable dt = new DataTable();
dt.column.add("id", typeof(int));
dt.column.add("fname", typeof(string));
dt.column.add("lname", typeof(string));
for (int = 0; i < 4; i++)
{
dt.Rows.Add(1, "shivu", "Nagarabetta");
}
DataTable dtInsertRows = dt;
//dtInsertRows.Columns.Remove("itemid");
using (SqlBulkCopy sbc = new SqlBulkCopy(connectionstring))
{
sbc.DestinationTableName = "tablename";
// Number of records to be processed in one go
sbc.BatchSize = 2;
// Map the Source Column from DataTabel to the Destination Columns in SQL Server 2005 Person Table
sbc.ColumnMappings.Add("id", "id");
sbc.ColumnMappings.Add("fname", "fname");
sbc.ColumnMappings.Add("lname", "lname");
// Number of records after which client has to be notified about its status
sbc.NotifyAfter = dtInsertRows.Rows.Count;
// Event that gets fired when NotifyAfter number of records are processed.
sbc.SqlRowsCopied += new SqlRowsCopiedEventHandler(sbc_SqlRowsCopied);
// Finally write to server
sbc.WriteToServer(dtInsertRows);
sbc.Close();
}