Assigning null value to an integer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
How can I assign null to an integer. This doesn't work
Dim intMyValue As Integer
intMyVal = System.DBNull.Value
Thanks in advance,
Roy
 
Marcie,
In a report I need to replace a value of integer column from zero to blank.
Any suggestions?
 
There are 2 things here:

- A integer field in the database can contain nulls, but the Integer type of
the .NET Framework is not nullable. In this case you must create a nullable
type (search Google for some implementations) or to use the Integer value
with a special value to denote null (and zero may not be the best option,
since it can be a valid value depending on your domain)

- You need to convert "0" to "" in your reports. For this you need a
conversion routine, for example i.ToString("#")

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Roy said:
How can I assign null to an integer. This doesn't work
Dim intMyValue As Integer
intMyVal = System.DBNull.Value

'Integer' is not nullable. What you can do is writing a wrapper class
around 'Integer' that provides support for a 'null' value, use 'SqlInt32'
instead or wait for .NET 2.0 which contains nullable types.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top