Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code-based connections to SQL
Message
From
06/01/2003 19:53:50
Irv Adams
MSC Managed Care, Inc.
Florida, United States
 
General information
Forum:
Visual Basic
Category:
SQL Server
Miscellaneous
Thread ID:
00735237
Message ID:
00738608
Views:
11
This is very helpful, it will get me well on my way towards VB-awareness !!

Thank you very much!

-Irv.


>Follow these steps
>
>1. Start a new Standard EXE project
>2. Add a reference to Microsoft ActiveX Data Objects 2.x Library
>3. Add 2 textboxes and 2 command buttons to the form
>4. Add these declarations to the General Declarations of your code
>
Dim mobjCN As ADODB.Connection
>Dim mobjRS As ADODB.Recordset
>5. Create a sub to fill controls from your recordset
>
Private Sub FillControls()
>    Text1.Text = mobjRS.Fields(0).Value
>    Text2.Text = mobjRS.Fields(1).Value
>End Sub
>
>6. Add this code to the Form_Load event to connect to the database, retreive some data and fill textboxes
>
Private Sub Form_Load()
>    Set mobjCN = New ADODB.Connection
>    With mobjCN
>        .CursorLocation = adUseClient
>        .ConnectionString = "Provider=sqloledb;" & _
>                            "Data Source=(local);" & _
>                            "Initial Catalog=Pubs;" & _
>                            "Integrated Security=SSPI"
>        .Open
>    End With
>
>    Set mobjRS = New ADODB.Recordset
>    With mobjRS
>        .CursorLocation = adUseClient
>        .CursorType = adOpenStatic
>        .LockType = adLockReadOnly
>        .Open "SELECT * FROM Authors", mobjCN
>    End With
>
>    FillControls
>End Sub
>7. Add this code to do a "previous" button
>
Private Sub Command1_Click()
>    mobjRS.MovePrevious
>    If mobjRS.BOF Then mobjRS.MoveFirst
>    FillControls
>End Sub
>8. Add this code to do a "next" button
>
Private Sub Command2_Click()
>    mobjRS.MoveNext
>    If mobjRS.EOF Then mobjRS.MoveLast
>    FillControls
>End Sub
>
>That's it. It should be working now (if you have a Pubs database and a Authors table)!
>
>
>>I am relatively new to VB/SQL, and being an (old) FoxPro guy I am used to doing this somewhat differently, but my question is this:
>>
>>I can drag/drop ADOC controls on a VB Form, attach to my MSDE SQL Server, and use the Recordset methods and properties without much trouble. However, I want to raise my expertise up a notch; could someone provide me with an example of how to access the SQL engine entirely in code?
>>
>>I am using VB 6.0 and MSDE on a single machine.
>>
>>Many thanks!
>>
>>-Irv.
Previous
Reply
Map
View

Click here to load this message in the networking platform