refreshing data in a Datagrid with an ADO control
I have developed a program with DAO, but for some reasons in my job, I have
to port it now to ADO, but I have some problems:
An ADO recordset does not have the FindFirst method, so I can't search a
record with more than one key with the Find method(doesn't admit AND's and
OR's) so navigating through a recordset is very painfull. I have a procedure
that delete ranges of records of a table, so I have opted to do it manually
with an ADO command object and a SQL statement, and later refreshing the
data in the DataGrid with the Requery method. But the problem is
that the Requery executed at the final of the deleting process does not refresh
correctly. If I delete records 10 and 11, they remain in the grid, but if
I now delete records, for example 15 and 16, the 10 and 11 records now disapears
from the grid, and so on. I've tried everything, refreshing the Datagrid,
de ADO control, etc., but this behavior occurs allways. Also if I issue the
refresh method manually via a command button, after a deleted range of records
(that still are in the grid!!!) it works, and the grid now shows the correct
data.
Please, somebody tell me how can I refresh the DataGrid in the right way
!!
My english is not so good, but I think you will understand me.
Re: refreshing data in a Datagrid with an ADO control
Fabio,
Yo también sufrí cuando pase de DAO a ADO ya uqe el Recordset de ADO era
muy limitado con respecto al de DAO, pero eso fue hasta la versión 2.1, debes
bajar el service pack 4 y este problema se resuelve, además debes tratar
de utilizar otro tipo de cursor para el recordset para este tipo de problemas
utiliza el cursosr dinámico, de todas formas seguro tendras que cambiar muchas
de tus rutinas viejas ya que el recordset de DAO era muy poderozo y abierto.
Javier Vargas
Development Ing.
Royal Computers
"Fabio Quadrana" <quadrana@satlink.com> wrote:
>
>I have developed a program with DAO, but for some reasons in my job, I have
>to port it now to ADO, but I have some problems:
>An ADO recordset does not have the FindFirst method, so I can't search a
>record with more than one key with the Find method(doesn't admit AND's and
>OR's) so navigating through a recordset is very painfull. I have a procedure
>that delete ranges of records of a table, so I have opted to do it manually
>with an ADO command object and a SQL statement, and later refreshing the
>data in the DataGrid with the Requery method. But the problem is
>that the Requery executed at the final of the deleting process does not
refresh
>correctly. If I delete records 10 and 11, they remain in the grid, but if
>I now delete records, for example 15 and 16, the 10 and 11 records now disapears
>from the grid, and so on. I've tried everything, refreshing the Datagrid,
>de ADO control, etc., but this behavior occurs allways. Also if I issue
the
>refresh method manually via a command button, after a deleted range of records
>(that still are in the grid!!!) it works, and the grid now shows the correct
>data.
>Please, somebody tell me how can I refresh the DataGrid in the right way
>!!
>
>My english is not so good, but I think you will understand me.
Re: refreshing data in a Datagrid with an ADO control
Ante todo gracias por haber respondido a mi pedido de socorro !!
Te cuento que que tengo cierta experiencia previa con ADO antes de usarlo
con VB porque he desarrollado y trabajado con paginas web ASP usando precisamente
ADO para el acceso a bases de datos, pero nunca habia tenido la necesidad
de recorrer un recordset por una clave compuesta por varias columnas como
en el caso del mensaje. El metodo Find de ADO es extremadamente restringido,
y revisando los metodos del objeto recordset del libro ASP 3.0 Programmer's
Reference de Wrox (que cubre la version 2.5 de ADO) me encontre con que el
metodo Find aun funciona exactamente igual, o sea se puede buscar solo por
una columna. La alternativa que daba es filtrar el recordset por una condicion
( que esta si puede contemplar multiples columnas) para obtener el registro
deseado. Pero esto solo sirve para obtener un bookmark, porque la grilla
te queda mostrando solo ese registro. Pero el truco que encontre fue filtrar
-> obtener el bookmark -> sacar el filtro inmediatamente (el efecto no se
nota en pantalla) y posicionarme en el bookmark del registro que buscaba,
y a partir de ahi procesar el recordset como si hubiera hecho un FindFirst.
Pero como podras ver todo esto es muy rebuscado, por eso pense en ejecutar
un comando SQL con un objeto ADO command, y refrescar la grilla, pero aca
empezaron los problemas otra vez. Probe refrescar el recordset, hacer un
requery, refrescar el control, y no pasaba nada, los registros, aunque borrados,
seguian en el recordset. Si hacia por segunda vez otro borrado de un rango,
ahora los que desaparecian del recordset eran los primeros borrados, pero
los segundos permanecian. es como si hubiera un desfasaje en el refresco.
Llegue a poner un boton de prueba que hacia un Requery para refrescar la
grilla despues del borrado y efectivamente desaparecian los registros borrados
que aun estaban !!!.
Y cuando ya no sabia casi que mas hacer, se me ocurrio hacer antes un BeginTrans
y un CommitTrans despues de ejecutar el metodo Execute del objeto command,
y luego de hacer un simple refresh del control ADO, la grilla POR FIN se
refresco como correspondia.
Te puedo asegurar que busque por todos lados, probe de todo, pregunte a amigos,
lei todo lo que tuve a mano, y al final fui a encontrar la solucion cuando
ya estaba por entregarme.
No se si hay alguna otra forma para llegar al mismo resultado, y tampoco
se porque pasa lo que pasa si no inicias una transaccion, pero la cuestion
que esto NO LO DICE NI LO SUGIERE NADIE EN NINGUN LADO, lo tenes que descubrir
a pulmon.
Vale aclararte que el filtro a un recordset no se lo sacas poniendo la propiedad
Filter = "" o Filter = adFilterNone como dice en el libro. Si haces esto,
te quedas con una grilla vacia. Lo que tenes que hacer es ponerle un filtro
obvio que te incluya todos los registros y santo remedio (microsoft y la
p... que te p.... !!!!!!)
Ya estoy bajando el SP4 del VB6 (que pesado!!!), aunque para ser franco no
tengo demasiadas espectativas, pero por las dudas...
Espero que todo lo que te conte te haya servido de algo.
Quedemos en contacto para cualquier problema mutuo con este bendito VB.
Saludos,
PD.: Tu direccion de mail me fallo.
Ing. Fabio Quadrana
quadrana@satlink.com
Banco Ciudad de Buenos Aires.