Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with null value
Message
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01601518
Message ID:
01601544
Vues:
42
Try passing DbNull.Value:
        public virtual DbParameter CreateParameter(string parameterName, object value)
        {
            DbParameter parm = dbProvider.CreateParameter();
            parm.ParameterName = parameterName;
            if (value == null)
                value = DBNull.Value;
            parm.Value = value;
            return parm;
        }
+++ Rick ---

>Hi everybody,
>
>I am trying to conditionally assign null value to a parameter and it doesn't seem to work.
>
>Here is my current code
>
>
>insertCommand.Parameters.Add("@accessPassNo", SqlDbType.Decimal, 17).Value = (this.passTable == PassTable.Access) ? passNo : (Int64?)null;
>
>And it returns the following error
>
>The parameterized query '(@datetime datetime,@quantity int,@BenefitId int,@gstPassNo deci' expects the parameter '@accessPassNo', which was not supplied.
>
>So, my question is - how should I properly assign null value? I tried using DbNull.Value, but then I can not even compile that code because of the problem with types.
>
>Thanks in advance.
>
>UPDATE. I have an idea to try - instead of inline iif I'll try IF ELSE and assign DbNull.Value this way.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform