SqlDataSource - parameters?

  • Thread starter Thread starter realgeek
  • Start date Start date
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();?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top