Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-11-2004
Member
 
Join Date: Aug 2004
Location: Ahmedabad , Gujarat
Posts: 6
Handling NULL in ASP.NET

HI

I am using PgSQL as Database. Front End is asp.net.

I am reading values from database using Reader classes. For example

Dim x as string
x= memberReader.getString(0)

Now if the value of memberReader.getString(0) is null then its throwing an error.

Error is like "Object cannot be cast from DBNull to other types". Obviously it will give an error.

So how do I check whether the incoming value is null or not.

Not getting much help from Gooooogle.

Help me as soon as possible

thnx in advance
Reply With Quote
  #2  
Old 24-11-2004
Member
 
Join Date: May 2004
Location: 127.0.0.1:chennai
Posts: 37
Handling null values returned from database resultsets is different in .NET from VB6.

this function returns that the value os null
Code:
Public Function IsDBNull(ByVal dbvalue) As Boolean
     Return dbvalue Is DBNull.Value 
End Function
this function changes thevalue from null to ""
Code:
Public Function FixNull(ByVal dbvalue) As String
        If dbvalue Is DBNull.Value Then
            Return ""
        Else
            'NOTE: This will cast value to string if
             'it isn't a string.

            Return dbvalue.ToString
        End If
End Function
Reply With Quote
  #3  
Old 25-11-2004
Member
 
Join Date: Aug 2004
Location: Ahmedabad , Gujarat
Posts: 6
question

Hi

Still I have not got the solution.

I created the function as you suggested

Code:
Public Function IsDBNull(ByVal dbvalue) As Boolean
   Return dbvalue Is DBNull.Value 
End Function
And I am using that function to check whether the data that I have read is NULL or not

Code:
        Dim BirthDate as new Date
        Dim memberConnection As New NpgsqlConnection(StudentSpace.Global.ConString)
        Dim memberCommand As NpgsqlCommand
        Dim memberReader As NpgsqlDataReader

        id = uId

        memberCommand = New NpgsqlCommand("select BirthDate from Student where UserID=:ID", memberConnection)
        memberCommand.Parameters.Add(":ID", NpgsqlTypes.NpgsqlDbType.Integer).Value = id
        memberConnection.Open()
        memberReader = memberCommand.ExecuteReader()
        memberReader.Read()

        If Not IsDBNull(memberReader.GetDateTime(0)) Then ' Ur Function Call
            BirthDate = memberReader.GetDateTime(0)
        End If
Then also I am getting the error

Error is Object cannot be cast from DBNull to other types.

What should I do
Reply With Quote
  #4  
Old 21-09-2005
Member
 
Join Date: Sep 2005
Location: India
Posts: 3
Re: Handling NULL in ASP.NET

Hello,

i am also a lover for asp.net and happy to meet friends like you.

I suggest you to ask few questions on www.asp.net

if you are seriously planning to study, you should atleast visit here twice
a week.

plus i also suggest you to go for www.aspalliance.com

just watch out for asp.net 2 on 7th november. It will change your life
and the way you have been programming so far.

dotnetguy
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Handling NULL in ASP.NET"
Thread Thread Starter Forum Replies Last Post
Dereferencing NULL pointer in C++ TO-Phir Software Development 4 26-06-2011 07:42 PM
How to Use NULL in Microsoft Access? Soumen Software Development 4 04-02-2010 05:17 AM
How to Check Null Value in C#? sivaranjan Software Development 4 04-02-2010 04:49 AM
Assigning null value to value type in c#: Is it possible? Sheenas Software Development 5 27-11-2009 08:35 AM
What is null value? Swati Software Development 3 14-02-2009 04:39 PM


All times are GMT +5.5. The time now is 05:37 AM.