2010-05-18 13 views
0

Récemment, j'ai rencontré un problème; quand je lie un jeu d'enregistrements à DataGrid et exécuter l'application de la grille de données n'est pas remplie, même si recordset a donnéesProblème de Datagrid vide dans VB6

J'utilise le code suivant

Option Explicit 
Dim conn As New ADODB.Connection 
Dim cmd As New ADODB.Command 
Dim recordset As New ADODB.recordset 





Private Sub InitializeConnection() 
Dim str As String 

str = _ 
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _ 
    "Data Source=" + App.Path + "\phonebook.mdb;" & _ 
    "Persist Security Info=False" 

    conn.CursorLocation = adUseClient 

    conn.ConnectionString = str 

    conn.Open (conn.ConnectionString) 


End Sub 
Private Sub AbandonConnection() 
    If conn.State <> 0 Then 
     conn.Close 
    End If 
End Sub 
Private Sub Persons_Read() 

    Dim qry_all As String 

    ' qry_all = "select * from person,web,phone Where web.personid = person.id And phone.personid = person.id" 
    qry_all = "SELECT * FROM person" 

    Call InitializeConnection 

    cmd.CommandText = qry_all 
    cmd.CommandType = adCmdText 

    Set cmd.ActiveConnection = conn 


    If conn.State = 1 Then 

     Set recordset = cmd.Execute() 

    End If 

    Call BindDatagrid 


    Call AbandonConnection 


End Sub 
Private Function Person_Add() 

End Function 
Private Function Person_Delete() 

End Function 
Private Function Person_Update() 

End Function 
Private Sub BindDatagrid() 



    Set dg_Persons.DataSource = recordset 


    dg_Persons.Refresh 
End Sub 

Private Sub cmd_Add_Click() 
    Person_Add 
End Sub 

Private Sub cmd_Delete_Click() 
    Person_Delete 
End Sub 

Private Sub cmd_Update_Click() 
    Person_Update 
End Sub 

Private Sub Form_Load() 
    Call Persons_Read 

End Sub 

Private Sub mnu_About_Click() 
    frm_About.Show 

End Sub 

Merci à l'avance

Répondre

0

Il a été résolu en ne fermeture de la connexion juste après la requête!

1

Pour moi, j'ai pu corriger le problème en ajoutant cette ligne à mon code après avoir réglé le délai de connexion

conn.CursorLocation = adUseClient 

Ce problème a résolu mon