Solved

Update Integer Field When Null Value Is Being Passed as Parameter

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete HTML table rows 12 29
EF5: Question about Metadata Artifact Processing 4 15
mail.To.Add 5 26
Save ms data to server side. 19 44
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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