开发者

Adding multiple update params sqldatasource

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.


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)
    );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜