|
-
Jan 10th, 2004, 06:51 PM
#1
Thread Starter
Lively Member
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:
If IsDBNull(Me.DSlistboxes.Tables("tblCD").Rows(0)("CompanyID")) Then
CompanyIDEmpty = True
Else
CompanyIDEmpty = False
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
-
Jan 10th, 2004, 07:16 PM
#2
Hyperactive Member
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.
-
Jan 10th, 2004, 07:31 PM
#3
Thread Starter
Lively Member
Hi Richard,
thanks for your reply. I tried your code (adapted to my situation)
VB Code:
Dim Oledbstr As String
Oledbstr = "SELECT * FROM tblCD WHERE CDID=1"
Dim Cmd1 As OleDbCommand = New OleDbCommand(Oledbstr, DataConnection)
DataConnection.Open()
Dim dr1 As OleDbDataReader = Cmd1.ExecuteReader()
dr1.Read()
If Not IsDBNull(dr1("CompanyID")) Then
CompanyIDEmpty = False
Else
CompanyIDEmpty = True
End If
but it gives the same results: DBNull isn't detected.
Any ideas??
tom
-
Jan 10th, 2004, 08:28 PM
#4
PowerPoster
Code:
If Me.DSlistboxes.Tables("tblCD").Rows(0)("CompanyID") Is DbNull.Value Then
CompanyIDEmpty = True
Else
CompanyIDEmpty = False
End If
-
Jan 11th, 2004, 04:33 AM
#5
Hyperactive Member
? well I've run out of ideas can't see anything wrong
-
Jan 11th, 2004, 06:14 AM
#6
Thread Starter
Lively Member
Thanks for the replies.
I set the DbNull value as follows:
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|