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)
);
}
精彩评论