Re: Returning Null value instead of contents of field

From: Royboy (Royboy_at_discussions.microsoft.com)
Date: 02/24/05


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
>
>
>



Relevant Pages

  • Re: ADO Record Count
    ... this was the case that hit me. ... Main factor seems to be the a combination of cursor type and cursor location ... >> try to process records that aren't there. ... Checking EOF and BOF fixed it. ...
    (microsoft.public.vb.database.ado)
  • RE: Find and Find Next
    ... In a command button click event have the following: ... Do Until .EOF ... certain criteria and the cursor goes to that record. ...
    (microsoft.public.access.formscoding)
  • Re: EM_SCROLLCARET problem
    ... >I'm using RichEdit to display Div. ... >It does put the cursor at the eof ok, but the eof is not alwise at the ... >How can I fix this that the eof is at the bottom of RE? ... Try forcing the cursor to the top of the file before using ...
    (alt.comp.lang.borland-delphi)
  • Re: Crazy Readonly
    ... > EOF() in the bound alias. ... Or maybe the cursor got lost entirely. ...
    (microsoft.public.fox.programmer.exchange)