Database Connectivity wrt Visual Basic

Database Connectivity wrt Visual Basic

Post by Joshu » Wed, 12 Nov 2003 13:45:16



Hello All what I would like to know is how do I embed and
run my SQL queries in a Visual Basic enviroment.I want to
be able to access my SQL database through VB.
I really want this to work..

Thanks

 
 
 

Database Connectivity wrt Visual Basic

Post by Adam Machani » Wed, 12 Nov 2003 16:23:59


Look up ADODB.


Quote:> Hello All what I would like to know is how do I embed and
> run my SQL queries in a Visual Basic enviroment.I want to
> be able to access my SQL database through VB.
> I really want this to work..

> Thanks


 
 
 

1. Help with rudimentary Visual Basic 5.0 database connectivity

I have an Access database (actually built with VB4 datamanager) with
one table, "Clients" and three fields: "ClientID" as a long integer,
"ClientLastName" and "ClientFirstName" as strings.  I have populated
the table with test data.

I've built a simple UserForm ("DataAccessTest") in Word's VBA just to
test database connectivity.  The form has three editboxes
"txtClientID", "txtClientLastName" and "txtClientFirstName".  It also
has four command buttons "cmdMoveFirst", "cmdMovePrevious",
"cmdMoveNext" and "cmdMoveLast".

I've got the following code:

Public Sub PopulateDialog()
    lngClientID = rs.Fields("ClientID").Value
    DataAccessTest.txtClientID.Text = Str(lngClientID)
    strClientLastName = rs.Fields("ClientLastName").Value
    DataAccessTest.txtClientLastName.Text = strClientLastName
    strClientFirstName = rs.Fields("ClientFirstName").Value
    DataAccessTest.txtClientFirstName.Text = strClientFirstName
End Sub

Private Sub cmdMoveFirst_Click()
    rs.MoveFirst
    Call PopulateDialog
End Sub

Private Sub cmdMoveLast_Click()
    rs.MoveLast
    Call PopulateDialog
End Sub

Private Sub cmdMoveNext_Click()
    rs.MoveNext
    If rs.EOF = True Then
        rs.MoveLast
    End If
    Call PopulateDialog
End Sub

Private Sub cmdMovePrevious_Click()
    rs.MovePrevious
    If rs.BOF = True Then
        rs.MoveFirst
    End If
    Call PopulateDialog
End Sub

Private Sub txtClientLastName_Change()

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
    Dim lngClientID As Long
    Dim strClientLastName As String
    Dim strClientFirstName As String
    Dim wrkSpace As Workspace
    Set wrkSpace = CreateWorkspace(Name:="", UserName:="admin",
Password:="", usetype:="dbUseJet")
    Dim db As Database
    Set db = wrkSpace.OpenDatabase(Name:="E:\Test DB.mdb")
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Clients", dbOpenDynaset)
    Set rs = db.OpenRecordset("Clients")
    Call PopulateDialog
End Sub

Any help would be greatly appreciated.

2. visionware in the UK

3. OH-CINCINNATI-105470--Visual Basic-ORACLE-Visual C++-MFC-OOD-Visual Basic Programmer

4. 2 archecker questions

5. Open Connection to Access 2000

6. Pick Telecommuting Wanted