Solved

Update Integer Field When Null Value Is Being Passed as Parameter

Posted on 2010-11-26
3
688 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
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
Comment Utility
yes "angelIII:" is 100% right.
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 250 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now