I am trying to insert data using a stored procedure that has two tables. This first table is data is through text boxes the second data is through a grid which I stored in the database and passed to be inserted. The problem is when reading datatable and inserting it says there are too many parameter which happens to add in the for loop. Any suggestion how to handle this as the SP? Thanks in advance.
CODE:
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = strConnection;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = 120;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "insFamilyDetails";
cmd.Parameters.AddWithValue("@strHusbandName", strHusbandName);
cmd.Parameters.AddWithValue("@strRelation", strRelation);
....
....
// Child Details
for (int i = 0; i < strChildredDetails.Rows.Count; i++)
{
cmd.Parameters.AddWithValue("@strChildName", strChildredDetails.Rows[i][0].ToString());
cmd.Parameters.AddWithValue("@strDOB", strChildredDetails.Rows[i][1]);
cmd.Parameters.AddWithValue("@strBaptisedon", strChildredDetails.Rows[i][2]);
cmd.Parameters.AddWithValue("@strFirstComOn", strChildredDetails.Rows[i][3]);
cmd.Parameters.AddWithValue("@strConfirmedOn", strChildredDetails.Rows[i][4]);
cmd.Parameters.AddWithValue("@strMarried", "0");
cmd.Parameters.AddWithValue("@strAlive", "1");
}
conn.Open();
ReturnValue = Convert.ToBoolean(cmd.ExecuteNonQuery());
conn.Close();
}
catch (Exception e)
{
DL_LogAppErrors(e.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, "Insert Family Details");
return ReturnValue;
}
return ReturnValue;