Solved

Update Integer Field When Null Value Is Being Passed as Parameter

Posted on 2010-11-26
3
689 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
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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

15 Experts available now in Live!

Get 1:1 Help Now