I want to store multiple rows from a gridview to the database through the procedure. If there is only one row in the gridview, my code executes properly, but if there are several rows, it throws an error
Procedure or function insertDetails has too many arguments specified
Here is my C# code:
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count;i++ )
{
cmd.CommandText = "insertDetails";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", GridView1.Rows[i].Cells[2].Text);
cmd.Parameters.AddWithValue("@name", GridView1.Rows[i].Cells[3].Text);
cmd.Parameters.AddWithValue("@email", GridView1.Rows[i].Cells[4].Text);
cmd.Parameters.AddWithValue("@contact", GridView1.Rows[i].Cells[5].Text);
cmd.Parameters.AddWithValue("@Addres", GridView1.Rows[i].Cells[6].Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
}
}