i am trying to insert records from gridview to database by using below code,but record is not getting insert,please have a look.
- protected void Button1_Click(object sender, EventArgs e)
- {
- foreach (GridViewRow row in this.GridView1.Rows)
- {
- if (row.RowType == DataControlRowType.DataRow)
- {
-
- SqlCommand cmd = new SqlCommand("INSERT INTO tbl_Books VALUES(@B_Name,@B_IBN,@QTY)", con);
- cmd.Parameters.AddWithValue("@B_Name", row.Cells[0].Text);
- cmd.Parameters.AddWithValue("@B_IBN", row.Cells[1].Text);
- cmd.Parameters.AddWithValue("@QTY", row.Cells[2].Text);
- con.Open();
- cmd.ExecuteScalar();
- con.Close();
- }
- }
- }