Re: add data from a datagrid

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



diaExcel wrote:

I have an application in vb 6.0 using ADO and Access, and I try to
add all data from a datagrid in database but I can't. I don't know
what can I do, I use on a form a datagrid, and a commandbutton. The
code of fill out of datagrid is:


With rstincarca
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
End With
sirulSQL = "SELECT * FROM unifi order by area_name asc"
rstincarca.Open sirulSQL, Conex
Set dgImport.DataSource = rstincarca

nRows = rstincarca.RecordCount

First, you might try a simple MoveLast, MoveFirst, right after you open
rstincarca. Otherwise the RecordCount property may not be correct.

Second, ask yourself why you are using adUseServer and adOpenKeyset. A keyset
cursor may not retrieve all the records until they are needed, so RecordCount
might not work correctly.

Another option would be to open a small recordset using
"SELECT COUNT(*) As RecCount FROM unifi"

This would let the database server count up the records, and tell you how many
there were.



.


Quantcast