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:

'***************************************************
Dim sirulSQL As String
Dim rstincarca As ADODB.Recordset
Set rstincarca = New ADODB.Recordset
If Not rstincarca.State = adStateClosed Then
rstincarca.CancelUpdate
rstincarca.Close
End If
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
'***********************************************
and for add data I use that code:

Private Sub cmdAccept_Click()
'****************************************

Dim rstadd As ADODB.Recordset
Set rstadd = New ADODB.Recordset
If Not rstadd.State = adStateClosed Then
rstadd.CancelUpdate
rstadd.Close
End If
With rstadd
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
End With

Dim siruladd As String

siruladd = "select * from carriers_rates "
rstadd.Open siruladd, Conex
Dim n As Long
nRows = rstincarca.RecordCount
With rstadd

.Filter = "carrier_code='" & frmImport!txtCarrierCode.Text & "' AND
concatenate_code_by_carrier='" & frmImport!dgImport.Columns(1).Text & "' AND
data='" & frmImport!dtpData.Value & "' "
If .RecordCount = 0 Then
For n = 0 To nRows - 1
dgImport.Row = n
.AddNew
rstadd!carrier_code = frmImport!txtCarrierCode.Text
rstadd!area_name = frmImport!dgImport.Columns(0).Text
rstadd!concatenate_code_by_carrier = frmImport!dgImport.Columns(1).Text
rstadd!Rate = frmImport!dgImport.Columns(2).Text
rstadd!effective_date = frmImport!dgImport.Columns(3).Text
rstadd!Data = frmImport!dtpData.Value
.Update
rstincarca.MoveNext
Next n
Else
MsgBox ("Inregistrarea a fost facuta!")

optApplyID.Enabled = True
optViewNewID.Enabled = True
End If
End With
End Sub


and I add just the visiblerow of datagrid and I want to add all the data
from datagrid because sometimes i have in datagrid 7500 rows and I can't to
click every time on the button to add the data.

Please help me because i had to finish this project long time ago, and I
couldnt because of that.

Is someone to find a solution for that problem, I can't find anytingh, I
don't know what can i use for this adding.

Thank you very much in advance.

Re: add data from a datagrid by Steve

Steve
Mon Jan 07 21:26:19 CST 2008

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.




Re: add data from a datagrid by diaExcel

diaExcel
Wed Jan 09 08:26:03 CST 2008

Please help me, I tried but is giving me an error: "invalid row number" and
in table is adding just 91 rows from 1500 rows, what can I do?

Thank you.

"Steve Gerrard" wrote:

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