Empty Datagrid problem in VB6
Posted
by Hybrid SyntaX
on Stack Overflow
See other posts from Stack Overflow
or by Hybrid SyntaX
Published on 2010-05-18T14:59:38Z
Indexed on
2010/05/18
15:00 UTC
Read the original article
Hit count: 162
Hello
Recently, i encountered a problem; when I bind a recordset to datagrid ,and run the application the datagrid is not populated even though recordset has data
I use the following code
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
Thanks in advance
© Stack Overflow or respective owner