RE: [ODBC] Visual Basic and PostgreSQL ODBC

Lists: pgsql-generalpgsql-odbc
From: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>
To: "'Ryan C(dot) Bonham'" <Ryan(at)srfarms(dot)com>, pgsql-odbc(at)postgresql(dot)org
Cc: pgsql-general(at)postgresql(dot)org
Subject: RE: [ODBC] Visual Basic and PostgreSQL ODBC
Date: 2001-07-30 07:19:38
Message-ID: 8568FC767B4AD311AC33006097BCD3D61A2D56@woody.vale-housing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-odbc

> -----Original Message-----
> From: Ryan C. Bonham [mailto:Ryan(at)srfarms(dot)com]
> Sent: 27 July 2001 18:00
> To: pgsql-odbc(at)postgresql(dot)org
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: [ODBC] Visual Basic and PostgreSQL ODBC
>
>
> Hi,
>
>
> Ok I have a problem, that I need to find a fix or workaround
> for. I have a Visual Basic 6 application that calls on a
> PostgreSQL database. I have code that calls a table and runs
> a loop on it, deleting recordsets until the recordcount
> equals a certain number.. The code deletes the records fine,
> the problem is the recordcount doesn't change.. Does anyone
> know what is going on and how to fix it? Thank you
>
>
> Ryan
>
> VB CODE
>
> rstRecord2.MoveFirst
> Do Until rstRecord2.RecordCount = 0
> rstRecord2.Delete
> rstReocrd2.MoveNext
> Debug.Print rstRecord2.RecordCount
> Loop

Try the following:

rstRecord2.MoveLast
rstRecord2.MoveFirst
Do Until rstRecord2.RecordCount = 0
rstRecord2.Delete
rstRecord2.MoveNext
Debug.Print rstRecord2.RecordCount
Loop

The RecordCount property normally remains at zero until you've moved to the
end of the recordset, hence you need to MoveLast first. This can be a
resource issue though if you have large recordsets as this will cause the
entire recordset to be read from PostgreSQL. If you can though, you will
probably be better off executing a DELETE FROM sql query, and then
refreshing the recordset, or if you are always deleting all records in the
recordset, try:

rstRecord2.MoveFirst
While Not rstRecord2.EOF
rstRecord2.Delete
rstRecord2.MoveNext
Wend

regards, Dave.