Help me with this error occurs if I execute a stored procedure more than once in the following process: the error occurs inside the foreach when it enters a second time
public string habilitarcredencial(int idusuariom, GridView sistemas, int reintentar)
{
string strsql;
strsql = "HabilitarCredencial";
CadenaConexion cc = new CadenaConexion();
SqlConnection cnn = new SqlConnection(cc.ConnectionString());
SqlCommand da = new SqlCommand();
da.Connection = cnn;
cnn.Open();
da.CommandType = CommandType.StoredProcedure;
string error = string.Empty;
string erroracumulador = string.Empty;
foreach (GridViewRow item in sistemas.Rows)
{
TextBox boton = (TextBox)item.FindControl("FechaI");
TextBox boto2 = (TextBox)item.FindControl("FechaF");
if (boton.Text!="" && boto2.Text!="")
{
da.Parameters.Add("@idusuario", SqlDbType.Int).Value = idusuariom;
da.Parameters.Add("@idsistema", SqlDbType.Int).Value =
item.Cells[2].Text.ToString();
da.Parameters.Add("@fechai", SqlDbType.DateTime).Value = boton.Text;
da.Parameters.Add("@fechan", SqlDbType.DateTime).Value = boto2.Text;
da.Parameters.Add("@reintentar", SqlDbType.Bit).Value = reintentar;
da.Parameters.Add("@error", SqlDbType.VarChar, 8000).Direction =
ParameterDirection.Output;
da.CommandText = strsql;
da.ExecuteNonQuery();
erroracumulador = Convert.ToString(da.Parameters["@error"].Value);
error = " "+error+" "+ erroracumulador +" ";
}
}
cnn.Close();
return error;
}