how to show the results of MS Access database query in Visual basic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eglute
    New Member
    • Nov 2006
    • 24

    how to show the results of MS Access database query in Visual basic

    Hello I want to show the results of MS Access database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is:

    Dim db As Database
    Dim rec As Recordset

    Private Sub Command1_Click( )
    Set db = OpenDatabase("t he patht of database")
    MsgBox "database is open"
    Set rec = db.OpenRecordse t("SELECT DISTINCT asmenu_info.Var das FROM asmenu_info;")
    While Not rec.EOF
    Label1.Print rec!vardas
    rec.MoveNext
    Wend
    rec.Close
    db.Close
    End Sub

    If i do this with second form everythig is ok, but I want to do this with label or text box
  • bhar
    Banned
    New Member
    • Apr 2006
    • 37

    #2
    Hi,

    Private Sub Form_Load()
    Set rsgroup = New ADODB.Recordset
    Set rsaccount = New ADODB.Recordset
    rsgroup.CursorL ocation = adUseClient
    rsaccount.Curso rLocation = adUseClient
    rsgroup.Open “SELECT * FROM NGROUP WHERE GHIDDEN <> -1”, CN, adOpenDynamic, adLockOptimisti c, adCmdText
    rsaccount.Open “SELECT * from PARTY”, CN, adOpenDynamic, adLockOptimisti c
    If rsaccount.Recor dCount > 0 Then
    Do While rsaccount.EOF = False
    List1.AddItem rsaccount(“pnam e”)
    rsaccount.MoveN ext
    Loop
    rsaccount.MoveF irst
    End If
    If rsaccount.Recor dCount > 0 Then
    mname = rsaccount!PName
    mdes = rsaccount!pdes
    madd1 = rsaccount!addre ss1
    madd2 = rsaccount!addre ss2
    mphone = rsaccount!phone
    mfax = rsaccount!fax
    mcity = rsaccount!city
    mamount = rsaccount!opamt
    End If
    mname.Enabled = False
    mdes.Enabled = False
    madd1.Enabled = False
    madd2.Enabled = False
    mcity.Enabled = False
    mphone.Enabled = False
    mfax.Enabled = False
    mamount.Enabled = False
    savebutton.Enab led = False
    cancelbutton.En abled = False
    Newbutton.Enabl ed = True
    Editbutton.Enab led = True
    deletebutton.En abled = True
    End Sub

    Database programming in Visual basic

    Comment

    Working...