PRB: Invalid Use of NULL Assigning Text Fields Value
ID: Q198300
|
The information in this article applies to:
-
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0
SYMPTOMS
When attempting to assign the value of a SQL Server text field to a text
box control the following error may occur:
Invalid Use of Null.
The SQL Server text field may actually contain data in it, but even
checking the value while in Debug mode can cause the fields contents to
change to NULL.
CAUSE
Neither Remote Data Objects (RDO) or ActiveX Data Objects (ADO) are caching
the text field value so the requests are sent back to the dataprovider. The
cursor engine may not have enough information to request that field value
again from the server.
RESOLUTION
There are several workarounds for this behavior:
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
- Create a Standard EXE project in Visual Basic.
- Add a Reference to Microsoft Remote Data Object 2.0.
- Add a multiline text box and a command button to the form.
- Place the following code in the command button Click event:
Dim en As rdoEnvironment
Dim cn As rdoConnection
Dim rs As rdoResultset
Dim sql As String
sql = "Select * from pub_info"
Set en = rdoEngine.rdoEnvironments(0)
With en
.CursorDriver = rdUseOdbc
' uncomment the following line for first workaround
'.CursorDriver = rdUseClientBatch
End With
Dim cnStr As String
cnStr = "driver={SQL Server};server=myserver;" & _
"database=pubs;uid=sa;pwd="
Set cn = en.OpenConnection(DSName:="", Prompt:=rdDriverNoPrompt, _
Connect:=cnStr)
Set rs = cn.OpenResultset(sql, rdOpenDynamic, rdConcurValues, _
rdAsyncEnable)
While rs.StillExecuting
DoEvents
Wend
rs.MoveLast
MsgBox "RDO: " & Str(rs.RowCount) & " rows returned."
' Move back to first record.
rs.MoveFirst
' Uncomment the following two lines for the second workaround:
'Dim test As Variant
'test = rs!pr_info
' Check for null value before assigning.
If IsNull(rs!pr_info) Then
' Comment preceding line and uncomment following line for second
' workaround:
'If IsNull(test) Then
Text1.Text = ""
Else
' Assign value to text field if not NULL.
Text1.Text = rs!pr_info
' Comment preceding line and uncomment following line for second
' workaround:
'Text1.Text = test
End If
Do While Not rs.EOF
Debug.Print rs!pr_info
rs.MoveNext
Loop
rs.Close
cn.Close
en.Close
NOTE: Be sure to put your SQL Server name in the Connection string.
REFERENCES
For additional information, please see the following articles in the
Microsoft Knowledge Base:
Q194975 HOWTO: Sample Functions Demonstrating GetChunk and AppendChunk
Q153238 HOWTO: Use GetChunk and AppendChunk Methods of RDO Object
Additional query words:
Keywords : kbRDO kbSQLServ kbVBp kbVBp500 kbVBp600 kbGrpVBDB
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbprb