General discussion

Locked

VB6 and ADO Recordset

By setivi ·
I have two identical tables A and B, the same fields etc. but table B is the smaller of the two. I want to write or transfer every record from table A to table B whose value in the field "Payment" is true.

I am trying to avoid field by field assignments. There are two hundred fields. Writing an entire record at one swoop in the do or while loop is
my wish.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

VB6 and ADO Recordset

by rmrSalisbury In reply to VB6 and ADO Recordset

The simplest way to accomplish what you want is to let the database do the work, using the ADO command object

Dim adoCommand As New ADODB.Command

With adoCommand
.ActiveConnection = conn
.CommandText = "INSERT INTO tableB SELECT* FROM tableA WHERE payment = True"
.Execute
End With

Collapse -

VB6 and ADO Recordset

by setivi In reply to VB6 and ADO Recordset

The question was auto-closed by TechRepublic

Collapse -

VB6 and ADO Recordset

by VinnyD In reply to VB6 and ADO Recordset

The easiest way I know is to use an SQL Query.

INSERT INTO tableb
SELECT *
FROM tablea
WHERE field="Payment";

Collapse -

VB6 and ADO Recordset

by setivi In reply to VB6 and ADO Recordset

The question was auto-closed by TechRepublic

Collapse -

VB6 and ADO Recordset

by Guan In reply to VB6 and ADO Recordset

You can loop in the recordset that contain all selected rows which have value in the field "Payment" is true and using following procedure to assign all fields in the recordset.

Private Sub CopyRS(ByVal rsSource As ADODB.Recordset, ByVal rsDest As ADODB.Recordset)
Dim F As ADODB.Field
If rsSource.State = adStateClosed Then Exit Sub
If rsSource.EOF And rsSource.BOF Then Exit Sub
If rsSource.CursorType <> adOpenForwardOnly Then
If Not rsSource.EOF And Not rsSource.BOF Then
rsSource.MoveFirst
End If
End If

Do While Not rsSource.EOF
rsDest.AddNew
For Each F In rsSource.Fields
If F.Type <> adChapter Then rsDest(F.Name).Value = F.Value
Next F
rsDest.Update
rsSource.MoveNext
Loop

End Sub

Collapse -

VB6 and ADO Recordset

by setivi In reply to VB6 and ADO Recordset

The question was auto-closed by TechRepublic

Collapse -

VB6 and ADO Recordset

by setivi In reply to VB6 and ADO Recordset

This question was auto closed due to inactivity

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums