AoA
I am Inserting Data From DataGridview to Sql2005.It Insert Perfectely.
The Problem is that when i insert record it alway insert 0 row with my other rows
The Code is below
try
{
string con = "Data Source = FLOWER-PC;Database = MYFIRSTDATABASE;Integrated Security = True";
SqlConnection cn = new SqlConnection(con);
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
for (int i =0; i < dataGridView1.Rows.Count; i++)
{
cmd.CommandText = "INSERT INTO PERSONALINFORMATION(pid,firstname) values('"
+ dataGridView1.Rows[i].Cells["pid"].Value + "','"
+ dataGridView1.Rows[i].Cells["firstname"].Value + "')";
cmd.ExecuteNonQuery();
}
cn.Close();
MessageBox.Show("Record Inserted Successfully");
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
Please Help and send me its Solution as soon as possible