I use this code to insert data from the excel sheet in to sql server table. Is there another way to make it fast because it takes a lot of time to insert records in it.
private void Button2_Click(object sender, EventArgs e)
{
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
cmd.CommandText = "INSERT INTO tabl(Name_Arabic, CIVILIDD , gender, NATIONALITY, TEL8, TEL7, TEL6, TEL5, TEL4, TEL3, TEL2, TEL1, Work_Adderss, Home_Address, Home_Address2, Name_eng, username, note, Governorate, City, Block, Street, Avenue, House, Floor, flat, address_note, status, confirmation,Irregularities,Irregularities_date)values" +
"(N'" + dataGridView1.Rows[i].Cells[0].Value + "',N'" + dataGridView1.Rows[i].Cells[1].Value + "',N'" + dataGridView1.Rows[i].Cells[2].Value + "',N'" + dataGridView1.Rows[i].Cells[3].Value + "',N'" + dataGridView1.Rows[i].Cells[4].Value + "',N'" + dataGridView1.Rows[i].Cells[5].Value + "',N'" + dataGridView1.Rows[i].Cells[6].Value + "',N'" + dataGridView1.Rows[i].Cells[7].Value + "',N'" + dataGridView1.Rows[i].Cells[8].Value + "',N'" + dataGridView1.Rows[i].Cells[9].Value + "',N'" + dataGridView1.Rows[i].Cells[10].Value + "',N'" + dataGridView1.Rows[i].Cells[11].Value + "',N'" + dataGridView1.Rows[i].Cells[12].Value + "',N'" + dataGridView1.Rows[i].Cells[13].Value + "',N'" + dataGridView1.Rows[i].Cells[14].Value + "',N'" + dataGridView1.Rows[i].Cells[15].Value + "',N'" + dataGridView1.Rows[i].Cells[16].Value + "',N'" + dataGridView1.Rows[i].Cells[17].Value + "',N'" + dataGridView1.Rows[i].Cells[18].Value + "',N'" + dataGridView1.Rows[i].Cells[19].Value + "',N'" + dataGridView1.Rows[i].Cells[20].Value + "',N'" + dataGridView1.Rows[i].Cells[21].Value + "',N'" + dataGridView1.Rows[i].Cells[22].Value + "',N'" + dataGridView1.Rows[i].Cells[23].Value + "',N'" + dataGridView1.Rows[i].Cells[24].Value + "',N'" + dataGridView1.Rows[i].Cells[25].Value + "',N'" + dataGridView1.Rows[i].Cells[26].Value + "',N'" + dataGridView1.Rows[i].Cells[27].Value + "',N'" + dataGridView1.Rows[i].Cells[28].Value + "',N'" + dataGridView1.Rows[i].Cells[29].Value + "',N'" + dataGridView1.Rows[i].Cells[30].Value + "')";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
MessageBox.Show("saved");
}
her im try to add the gridview data to the database and it is different from the duplicate answer