Re: Returning Null value instead of contents of field
From: Royboy (Royboy_at_discussions.microsoft.com)
Date: 02/24/05
- Next message: Luciano: "problem deleting a row using DeleteCommand"
- Previous message: Stephen Howe: "Re: sometimes it returns error message: Either BOF or EOF is true in my asp page and it has valid data"
- In reply to: Stephen Howe: "Re: Returning Null value instead of contents of field"
- Next in thread: Stephen Howe: "Re: Returning Null value instead of contents of field"
- Reply: Stephen Howe: "Re: Returning Null value instead of contents of field"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 23 Feb 2005 16:25:02 -0800
Steve
Good call on the cursor type change I misunderstood what was happening.
The cause of the problem does make more sense now.
If I am correct in my understanding of the situation.
When I use a Forward only cursor in SQL Server I can only read the contents
of the a nText field once.
Does this mean that I should copy the contents of the nText field into a
local variable before I use it or change my cursor?
eg
Dim varField As Variant
varField = rs("Description").Value
Debug.Print IIf(IsNull(varField), vbNullString, varField)
instead of my original code
Debug.Print IIf(IsNull(rs("Description").Value), vbNullString,
rs("Description").Value)
Does this mean I have written my code incorrectly and should always keep a
local copy of data before testing for a Null.
Is there a best practice article I can read to explain how I should be doing
this?
Thanks
P.S.
The test for EOF and BOF is to make sure the open statement had returned at
least one row. Ie if on the first read BOF and EOF are both true, I have an
empty recordset. Is this an overkill? Will a test for EOF be sufficient?
"Stephen Howe" wrote:
> 1) First, even though you request a adOpenForwardOnly cursor for rs2, you
> will only ever get back a adOpenStatic cursor because for client-sided, that
> is all ADO supports.
> Try printing the CursorType _AFTER_ a successful Open
>
> 2) This is suspect for a Forward-Only Server-sided cursor:
>
> > If Not (rs1.EOF And rs1.BOF) Then
> >
> > Call PrintResults(rs1)
> > Call PrintResults(rs1)
> > End If
>
> If rs1.BOF is True but rs1.EOF is False your code above will call
> PrintResults()
> But if rs1.BOF is True, you are not on any record, a MoveNext() is required.
>
> Try instead
>
> If Not rs1.EOF Then
> If rs1.BOF Then rs1.MoveNext() 'Not even on first record, advance
> End If
>
> If Not rs1.EOF Then
> Call PrintResults(rs1)
> Call PrintResults(rs1)
> End If
>
> Stephen Howe
>
>
>
- Next message: Luciano: "problem deleting a row using DeleteCommand"
- Previous message: Stephen Howe: "Re: sometimes it returns error message: Either BOF or EOF is true in my asp page and it has valid data"
- In reply to: Stephen Howe: "Re: Returning Null value instead of contents of field"
- Next in thread: Stephen Howe: "Re: Returning Null value instead of contents of field"
- Reply: Stephen Howe: "Re: Returning Null value instead of contents of field"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|