Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Null parameter problem

Reply
 
Old 09-10-2008   #1 (permalink)
E. Kwong


 
 

Null parameter problem

I have a function that takes two arguments



Public Function CheckThing(ByVal b As Boolean, ByVal s as String) As
String

:

The function is called from inside a FormView control like this:



<%#CheckThing(Eval("flag"),Eval("myfield"))%>



Everything works fine except when myfield has a null value: I'll then get
an error saying something like ".can not convert DBNull to string.."



What's the best way to handle situation like this? Thanks.



I'm using VS2005, and SQL Server database.





My System SpecsSystem Spec
Old 09-10-2008   #2 (permalink)


Vista Business x64
 
 

Re: Null parameter problem

There area number of ways. First, if you are okay with deciding there should be no nulls in this field from the db, modify the sproc that returns the data to replace myfield with ISNULL(myfield,'') in the T-SQL select statement.

There are ways to handle it in the app code as well. I have been using C#.NET since 2003, so I will have to pull up VS and figure out the equivalent VB.NET syntax. I'll post back later with that.
My System SpecsSystem Spec
Old 09-10-2008   #3 (permalink)


Vista Business x64
 
 

Re: Null parameter problem

Replace myfield with:

IIf(Eval("myfield") Is System.DBNull.Value, "", Eval("myfield"))

You can also change the parameter type to allow a DBNull to come across and handle it in the CheckThing function.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Script parameter problem PowerShell
Re: "Error: 'null' is null or not an object" when trying to view video Vista performance & maintenance
Gotcha: $null to [string] IS NOT $null PowerShell
Problem with WMI in WinPE - null: Invalid Syntax Error Vista installation & setup
How to best control parameter attributes and parameter parsing in your own scripts? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46