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.