Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with null value
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Problem with null value
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:
01601518
Vues:
53
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.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform