Results 1 to 6 of 6

Thread: IsDBNull function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84

    Question IsDBNull function

    Hi guys,

    Is there anybody who can help me with the IsDBNull function. I would like to use it to check if the field "CompanyID" in the datatable "tblCD" is a DBNull value.

    VB Code:
    1. If IsDBNull(Me.DSlistboxes.Tables("tblCD").Rows(0)("CompanyID")) Then
    2.             CompanyIDEmpty = True
    3.         Else
    4.             CompanyIDEmpty = False
    5.         End If

    I'm sure the row(0) contains a DBNull-value (I inserted it myself) but the function IsDBNull doesn't detect it because the boolean CompanyEmptyID is always false while it should be true for that row.

    What am I doing wrong? Or is there another way to check for dbnull values?

    Kind regards,

    Tom

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    don't understand here is my own working code:

    Dim cn1 As OledbConnection = New OledbConnection(DbNam)
    Dim Oledbstr As String = "Select CompanyName,Address1,Address2,Address3,Address4,StationeryChoice from SystemValues where SysVal = 1"
    Dim Cmd1 As OledbCommand = New OledbCommand(Oledbstr, cn1)
    cn1.Open()
    Dim dr1 As OledbDataReader = Cmd1.ExecuteReader()
    dr1.Read()

    If Not IsDBNull(dr1("CompanyName")) Then
    dv1.Value = dr1("CompanyName")
    Else
    dv1.Value = " "
    End If

    looks very much like your own.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    Hi Richard,

    thanks for your reply. I tried your code (adapted to my situation)

    VB Code:
    1. Dim Oledbstr As String
    2.         Oledbstr = "SELECT * FROM tblCD WHERE CDID=1"
    3.         Dim Cmd1 As OleDbCommand = New OleDbCommand(Oledbstr, DataConnection)
    4.         DataConnection.Open()
    5.         Dim dr1 As OleDbDataReader = Cmd1.ExecuteReader()
    6.         dr1.Read()
    7.  
    8.         If Not IsDBNull(dr1("CompanyID")) Then
    9.             CompanyIDEmpty = False
    10.         Else
    11.             CompanyIDEmpty = True
    12.         End If

    but it gives the same results: DBNull isn't detected.

    Any ideas??

    tom

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Code:
    If Me.DSlistboxes.Tables("tblCD").Rows(0)("CompanyID") Is DbNull.Value Then
                CompanyIDEmpty = True
            Else
                CompanyIDEmpty = False
            End If

  5. #5
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    ? well I've run out of ideas can't see anything wrong

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    Thanks for the replies.

    I set the DbNull value as follows:


    VB Code:
    1. DSlistboxes.Tables("tblCD").Rows(Me.BindingContext(DSlistboxes, "tblCD").Position)("CompanyID") = System.DBNull.Value

    I tried the code of hellswraith, but it also doesn't detect the dnull value. I'm getting hopeless here. I use an access database (access 2000)

    any ideas???

    thanks,

    tom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width