VB.Net 2005 Null Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shresthau
    New Member
    • Oct 2007
    • 1

    VB.Net 2005 Null Error

    Hello,
    I need help.

    I have problem for VB.Net 2005.
    My backend database is SQL Server 2005

    I wrote the following code:

    strSQL="Select FName, LName, MName FROM tblInfo"
    RsOpen(strSQL)
    If Rs.RecordCount> 0 Then
    Rs.MoveFirst

    txtFName.Text=R s.Fields("FName ").Value
    txtMName.Text=R s.Fields("MName ").Value
    txtLName.Text=R s.Fields("LName ").Value
    End If

    My problem is MName filed is null value. How can i check the null value?
    I tried IsNull function in VB but in VB.Net there is no IsNull function.
    Please anybody know the function for check IsNull ?

    RaJaN
  • semomaniz
    Recognized Expert New Member
    • Oct 2007
    • 210

    #2
    I think this will help you. I think in vb you will have to check for null value with the keyword nothing. The example is as follow

    [code = vb.net]
    Dim sTest As String
    If (sTest Is Nothing) Then
    Console.WriteLi ne("sTest is Null")
    End If
    [/code]

    In you case i belive this should work,
    Code:
    if (Rs.Fields("MName").Value IS Nothing) then[INDENT] txtMName.Text = "The value is NULL"[/INDENT]
    else[INDENT] txtMName.Text = Rs.Fields("MName").Value[/INDENT]
    end if
    hope this helps.

    semomaniz

    Originally posted by shresthau
    Hello,
    I need help.

    I have problem for VB.Net 2005.
    My backend database is SQL Server 2005

    I wrote the following code:

    strSQL="Select FName, LName, MName FROM tblInfo"
    RsOpen(strSQL)
    If Rs.RecordCount> 0 Then
    Rs.MoveFirst

    txtFName.Text=R s.Fields("FName ").Value
    txtMName.Text=R s.Fields("MName ").Value
    txtLName.Text=R s.Fields("LName ").Value
    End If

    My problem is MName filed is null value. How can i check the null value?
    I tried IsNull function in VB but in VB.Net there is no IsNull function.
    Please anybody know the function for check IsNull ?

    RaJaN

    Comment

    • Shashi Sadasivan
      Recognized Expert Top Contributor
      • Aug 2007
      • 1435

      #3
      what sort of data type is RS ?

      Comment

      • GayathriP
        New Member
        • Oct 2007
        • 17

        #4
        You can use isDBNull(<Field Value) to check for the NULL values.

        Comment

        Working...