Thread: Visual Basic and PostgreSQL ODBC

Visual Basic and PostgreSQL ODBC

From
"Ryan C. Bonham"
Date:
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


RE: Visual Basic and PostgreSQL ODBC

From
Dave Page
Date:

> -----Original Message-----
> From: Ryan C. Bonham [mailto:Ryan@srfarms.com]
> Sent: 27 July 2001 18:00
> To: pgsql-odbc@postgresql.org
> Cc: pgsql-general@postgresql.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.