R
realgeek
I have the following code:
SqlDataSource ds = new SqlDataSource();
ds.ConnectionString =
WebConfigurationManager.ConnectionStrings["AnketaDBConnectionString"].ToString();
ds.UpdateCommand = "ad_SetAnswer";
ds.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
ds.UpdateParameters.Add(new Parameter("@QuestionID"));
ds.UpdateParameters.Add(new Parameter("@Answer"));
foreach (RepeaterItem li in Repeater1.Items)
{
int QuestionID =
int.Parse(((HtmlInputHidden)li.FindControl("hdQuestionID")).Value);
int Answer =
int.Parse(((RadioButtonList)li.FindControl("rblAnswers")).SelectedValue);
ds.UpdateParameters["@QuestionID"].DefaultValue =
QuestionID.ToString();
ds.UpdateParameters["@Answer"].DefaultValue = Answer.ToString();
ds.Update();
}
On the very first loop iteration I get the following:
Procedure or Function 'ad_SetAnswer' expects parameter '@QuestionID',
which was not supplied.
What's up with that? How do I work with parameters in SqlDataSource?
In fact, is there a better way to model SqlCOmmand cmd = ...;
cmd.ExecuteNonQuery();?
SqlDataSource ds = new SqlDataSource();
ds.ConnectionString =
WebConfigurationManager.ConnectionStrings["AnketaDBConnectionString"].ToString();
ds.UpdateCommand = "ad_SetAnswer";
ds.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
ds.UpdateParameters.Add(new Parameter("@QuestionID"));
ds.UpdateParameters.Add(new Parameter("@Answer"));
foreach (RepeaterItem li in Repeater1.Items)
{
int QuestionID =
int.Parse(((HtmlInputHidden)li.FindControl("hdQuestionID")).Value);
int Answer =
int.Parse(((RadioButtonList)li.FindControl("rblAnswers")).SelectedValue);
ds.UpdateParameters["@QuestionID"].DefaultValue =
QuestionID.ToString();
ds.UpdateParameters["@Answer"].DefaultValue = Answer.ToString();
ds.Update();
}
On the very first loop iteration I get the following:
Procedure or Function 'ad_SetAnswer' expects parameter '@QuestionID',
which was not supplied.
What's up with that? How do I work with parameters in SqlDataSource?
In fact, is there a better way to model SqlCOmmand cmd = ...;
cmd.ExecuteNonQuery();?