protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.SubmitCustomers();
}
}
public void SubmitCustomers()
{
string constring = Convert.ToString(ConfigurationManager.ConnectionStrings["Connection"]);
SqlConnection con = new SqlConnection(constring);
try
{
DataTable Extbl = new DataTable();
Extbl.Columns.Add("customerId", typeof(int));
Extbl.Columns.Add("FirstName");
Extbl.Columns.Add("LastName");
Extbl.Columns.Add("Role");
Extbl.Columns.Add("Gender");
Parallel.For(1, 100, i =>
{
DataRow dr = Extbl.NewRow();
dr["customerId"] = i;
dr["FirstName"] = "A" + i;
dr["LastName"] = "10" + i;
dr["Role"] = "1";
dr["Gender"] = "M";
Extbl.Rows.Add(dr);
});
SqlBulkCopy objbulk = new SqlBulkCopy(con);
objbulk.DestinationTableName = "Customers";
objbulk.ColumnMappings.Add("FirstName", "FirstName");
objbulk.ColumnMappings.Add("LastName", "LastName");
objbulk.ColumnMappings.Add("Role", "Role");
objbulk.ColumnMappings.Add("Gender", "Gender");
con.Open();
objbulk.WriteToServer(Extbl);
con.Close();
}
catch (Exception ex)
{
throw ex;
}
}