Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update Integer Field When Null Value Is Being Passed as Parameter

Posted on 2010-11-26
3
Medium Priority
?
697 Views
Last Modified: 2012-05-10
I have a drop down list in which the user can select blank(null), 1, 2, or 3.
I need to get the selected value of the drop down list and pass it as a parameter to update the database file.  The field that is being updated with this value is an integer.
Here is the code that I'm using:
 e.Command.Parameters("@Action_Priority").Value = ddlPriority.SelectedValue
How can I get this to work when the value is null????
0
Comment
Question by:mmtcunningham1
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 34217533
this should do;
if  ddlPriority.SelectedValue = "" then
 e.Command.Parameters("@Action_Priority").Value = DBNull.Value
else
 e.Command.Parameters("@Action_Priority").Value = ddlPriority.SelectedValue
end if

Open in new window

0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34217605
yes "angelIII:" is 100% right.
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 1000 total points
ID: 34217658
If the parameter of the stored procedure has a default value of NULL, then you do not even have to pass in the null value.

SQL Procedure:
Action_Priority INT = NULL  --Null is default

.NET:
if  ddlPriority.SelectedValue <> "" then
    e.Command.Parameters("@Action_Priority").Value = ddlPriority.SelectedValue
end if
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question