forsters
asked on
C# SQL Parameters.AddWithValue(); - how to include a default value
hi experts,
I have a sql insert in my code behind that includes a number of parameters e.g.
cmd.Parameters.AddWithValu e("@matter Number", DDLMatterNo.SelectedValue) ;
I want additionally to set the default value to 0 on a couple of the parameters where the controls are only visible conditionally.
In a previous version of the page this was possible because the sql was written as a datasource:
<asp:ControlParameter ControlID="DDLMatterNo" PropertyName="selectedvalu e" Name="matterNumber" DefaultValue="0" />
But in the code behind the method only accepts 2 arguments so the below attempt gets a syntax error - how to overcome this?
cmd.Parameters.AddWithValu e("@matter Number", DDLMatterNo.SelectedValue, Convert.ToInt32(0));
I have a sql insert in my code behind that includes a number of parameters e.g.
cmd.Parameters.AddWithValu
I want additionally to set the default value to 0 on a couple of the parameters where the controls are only visible conditionally.
In a previous version of the page this was possible because the sql was written as a datasource:
<asp:ControlParameter ControlID="DDLMatterNo" PropertyName="selectedvalu
But in the code behind the method only accepts 2 arguments so the below attempt gets a syntax error - how to overcome this?
cmd.Parameters.AddWithValu
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
actually on closer inspection it doesn't even insert a null - just an empty space
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ok glad that I could make some helps here cheers
ASKER
I have selected my comment for the benefit of others trying to resolve the same, but all credit goes to Ryan for lighting the way, thank you.
ASKER