i need to insert 180 records using bulk insert, but for every 30 records need to increment id,
protected void Button2_Click(object sender, EventArgs e)
{
// String strConnection = "Data Source=(LocalDB)\v11.0;AttachDbFilename=ChitFund-DataBase.mdf;Integrated Security=True";
DataTable dt = new DataTable();
dt.Columns.Add("INITIATE_SEQUENCE", typeof(string));
dt.Columns.Add("INITIATE_CHITNO", typeof(string));
dt.Columns.Add("INITIATE_YEAR", typeof(int));
dt.Columns.Add("INITIATE_MONTH", typeof(string));
dt.Columns.Add("INITIATE_TOTALMONTH", typeof(string));
dt.Columns.Add("INITIATE_CLIENTS", typeof(string));
dt.Columns.Add("INITIATE_AMOUNT", typeof(int));
dt.Columns.Add("INITIATE_INST", typeof(int));
dt.Columns.Add("INITIATE_CUSTOMER", typeof(string));
dt.Columns.Add("INITIATE_installment", typeof(int));
dt.Columns.Add("INITIATE_STATUS", typeof(int));
for (int i = 0; i <= 2; i++ )
{
foreach (GridViewRow row in GridView1.Rows)
{
string INITIATE_SEQUENCE = row.Cells[0].Text;
string INITIATE_CHITNO = row.Cells[1].Text;
int INITIATE_YEAR = int.Parse(row.Cells[2].Text);
string INITIATE_MONTH = row.Cells[3].Text;
string INITIATE_TOTALMONTH = row.Cells[4].Text;
string INITIATE_CLIENTS = row.Cells[5].Text;
int INITIATE_AMOUNT = int.Parse(row.Cells[6].Text);
int INITIATE_INST = int.Parse(row.Cells[7].Text);
string INITIATE_CUSTOMER = row.Cells[8].Text;
int INITIATE_installment = int.Parse(row.Cells[9].Text);
int INITIATE_STATUS = int.Parse(row.Cells[10].Text);
dt.Rows.Add(INITIATE_SEQUENCE, INITIATE_CHITNO, INITIATE_YEAR, INITIATE_MONTH, INITIATE_TOTALMONTH, INITIATE_CLIENTS, INITIATE_AMOUNT, INITIATE_INST, INITIATE_CUSTOMER, INITIATE_installment, INITIATE_STATUS);
}
//using (SqlConnection con = new SqlConnection(strConnection))
//{
// con.Open();
// SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
// //Give your Destination table name
// sqlBulk.DestinationTableName = "TBL_INITIATE";
// sqlBulk.WriteToServer(dt);
// con.Close();
//}
using (SqlConnection con = new SqlConnection(strConnection))
{
con.Open();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "TBL_INITIATE2";
sqlBulk.WriteToServer(dt);
con.Close();
}
lblMsg.Text = "Details Inserted Successfully";
lblMsg.ForeColor = System.Drawing.Color.Green;
}
}