|
-
September 30th, 2004, 04:12 PM
#1
Null values from ADODB recordset
I am using disconnected datasets in an appliation, stored with an ADODB recordset into an .MDB database (MS Jet).
For testing, I add a new record, only partially filled out. No problem.
BUT when I retreive the record, and try to load it into the components on my form (text boxes, combo boxes, etc), the fields which I left blank won't load. The error message is "Invalid use of null", which happens regardless of the data type. Even if I try to convert the field into a sting (Cstr()), I get the same message.
How can I prevent this?
-
September 30th, 2004, 06:20 PM
#2
Re: Null values from ADODB recordset
I had a similar problem, and the only way I could find to get around it was as follows:
if isnull(adrTable.Fields("fld")) then
txtBox = ""
else
txtBox = adrTable.Fields("fld")
endif
HTH
JP
Please remember to rate all postings. 
-
September 30th, 2004, 08:38 PM
#3
Re: Null values from ADODB recordset
maybe if u set the default value of the field to '-' so that u always have value '-' if u don't provide them..so that it can't display it on the textbox..
it depends what ur app's needs
regards
-
October 1st, 2004, 12:26 PM
#4
Re: Null values from ADODB recordset
Thanks:
JP - I was afraid of that!
eric: That sounds interesting...shame we can't set the default value to " ".
-
October 1st, 2004, 04:26 PM
#5
Re: Null values from ADODB recordset
Database design dictates that you need a null for referential integrity / foreign key fields, anything else could have a space.
For example I have a helpdesk system, a user logs a call (we call this an issue), that issue may turn out to be a bug fix (we call this a StIR). My Issues table, has a field called STIR which points to the bug fix record. The rules in my database state that for every value in ISSUES.STIR, there must be a STIR record. When I populate this value with NULL, the database knows that there is no matching record, however if I populate it with something else, the database goes looking for a stir with that key.
Having said that, you said you are using a disconnected recordset, so if you are not planning on updating it, you could set up a loop that replaces null characters with another eg:
Code:
dim adrTable as adodb.recordset
dim adrField as adodb.field
'
' Open the recordset
'
for each adrField in adrTable.Fields
If isnull(adrField.Value) then
adrField.Value = " "
EndIf.
Next
HTH
JP
Please remember to rate all postings. 
-
October 2nd, 2004, 03:26 AM
#6
Re: Null values from ADODB recordset
Another quite easy way to prevent errors from occuring is to do the following.
Code:
textbox1.text = "" & rs("Field")
Works everytime for me ..
Hope it helps.
Regards,
Michael
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
|