Hi all,
Is it possible to use a variable as an update parameter in asp.net?
I have the page number to be updated stored in a variable called 'mypagenum', how would I write an update parameter using that value.
Thanks
Hi all,
Is it possible to use a variable as an update parameter in asp.net?
I have the page number to be updated stored in a variable called 'mypagenum', how would I write an update parameter using that value.
Thanks
You can do this in two ways:
1) Using onUpdating event:
protected void sqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters["@param_name"].Value = mypagenum;
}
2) Setting the default value of the parameter:
sqlDataSource1.UpdateParameters["param_name"].DefaultValue = mypagenum;
SQL Data Source object definition may look like this:
<asp:SqlDataSource ID="sqlDataSource1" runat="server"
ConnectionString="<some connection string>"
UpdateCommand="UPDATE table SET column = @param_name"
onUpdating="sqlDataSource1_Updating">
<UpdateParameters>
<asp:Parameter Name="param_name" />
</UpdateParameters>
</asp:SqlDataSource>