Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Null for a string
Message
From
07/05/2009 14:02:56
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01398411
Message ID:
01398417
Views:
72
This message has been marked as the solution to the initial question of the thread.
>>ItemNo is a string. You assign null to a string like this:
ItemNo = null;
What are you trying to do? Assigning null to the string parameter or to a field of the datatable?
>>
>>>How can I fix this code
>public InventoryDS.ItemsDataTable Find(string ItemNo, string description)  
>>>        {
>>>            if (ItemNo.Equals(string.Empty))
>>>            { ItemNo = DBNull.Value; } // Intellisense doesn't like it
>Both parameters set to allow DbNull.
>
>BTW, would it allow it if it's not declared as string? It didn't complain in the code window.

Naomi, it depends if your variable type is a Value type or a Reference type. A value type (int, decimal, etc) cannot have null assigned to it, so your best bet is to use the Nullable generic and declare like:
Nullable<int > myValue = null;
A reference type (string, classes) are values in the stack that point to values on the heap. When you declare a reference type as null, you are essentially point it at nothing.
Very fitting: http://xkcd.com/386/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform