1

This code is part of a SqlDataSource:

<UpdateParameters>
            <asp:Parameter Name="username" Type="String" />
            <asp:Parameter Name="first_name" Type="String" />
            <asp:Parameter Name="surname" Type="String" />     
   </UpdateParameters>  

How can i code this so i can add multiple parameters, since i can only seem to add one at a time. I do not wish to place these update params in my .aspx file since i wish to seperate my database related items.

SqlDataSourceUsers.UpdateParameters.Add(parameter);

Thanks.

2
  • What's wrong with adding them one at a time? Commented May 5, 2011 at 13:25
  • Hm nothing i suppose, i just dont like to see 8 times the same line. But it seems i have little choice on this mather. Commented May 5, 2011 at 13:29

1 Answer 1

1

You could place your params in a Dictionary (or list if using parameter objects) and then use a loop to add them...

var params = new Dictionary<string, string>
{
    {"param1", "value1"},
    {"param2", "value2"},
};

foreach(var param in params)
{
    SqlDataSourceUsers.UpdateParameters.Add(
        new SqlParameter(param.Key, param.Value)
    );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.