tags:

views:

21

answers:

2

Hello, all is in the title :-)

Some explanation :

In order to use a vb6 with C# (COM / Interop) I have a performance issue with Data Access. I don't know why but the code is four times slower in C# via Interop.

I'm trying to find a workaround and I would to replace the rdo by ADO to gain performance.

old code (with rdo) :

strSelect = _
        QUERY1 & ";" & _
        QUERY2 & ";" & _
        QUERY3 & ";" & _
        QUERY4 & ";" & _
        QUERY5 & ";" & _
        QUERY6

 'Fp.Cn is a rdoConnection
 Set Fp.rs = Fp.Cn.OpenResultset(strSelect)


'ComboBox 1
    Call LoadCombo(cboOne)
    Fp.rs.MoreResults
'ComboBox 2
    Call LoadCombo(cboTwo)
    Fp.rs.MoreResults
'ComboBox 3
    Call LoadCombo(cboThree)
    Fp.rs.MoreResults
'ComboBox 4
    Call LoadCombo(cboFour)
    Fp.rs.MoreResults
'ComboBox 5
    Call LoadCombo(cboFive)
    Fp.rs.MoreResults
'ComboBox 6
    Call LoadCombo(cboSix)
    Fp.rs.MoreResults
Fp.rs.Close

Now the code in LoadCombo :

Public Sub LoadCombo(ByRef cboComboBox As ComboBox, ByRef rslResultSet As rdoResultset)


 cboComboBox.Clear

    With rslResultSet
        While Not .EOF
            cboComboBox.AddItem .rdoColumns(1)
            cboComboBox.ItemData(cboComboBox.NewIndex) = .rdoColumns(0)
            .MoveNext
        Wend
    End With
End Sub

How to modify this code with ADO ?

Regards,

Florian

+1  A: 

For your recordset, you would want to use the following code:

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset

conn.Open "YourDSN", "username", "pwd" ' Or other appropriate conn string here

rs.Open strSelect, conn ' This is your OpenResultset equivalent

And then for each combobox, call

Call LoadCombo(cboOne, rs) 
Set rs = rs.NextRecordset  ' Instead of Fp.rs.MoreResults    
...

If you haven't already, you'll need to add the ADO reference to your project (probably Microsoft Active Data Objects 2.8)

LittleBobbyTables
OK, I'll test it !
Florian
It works fine but the performance are very slow to :(
Florian
I'm sorry to hear that! In rare instances, I've seen the DAO object (as opposed to ADO) work faster in VB6, but for interacting with C#, I'm not sure.
LittleBobbyTables
Thx ! Could you send me a link about that (comparison ADO vs DAO) ?
Florian
LittleBobbyTables
Thank you very much !
Florian
A: 

This is the nearest equivalent in ADO:

' Fp.Cn is an active and open ADODB.Connection  '
' Fp.rs is an ADODB.Recordset object  '

Set Fp.rs = Fp.Cn.Execute(strSelect)
onedaywhen