Results 1 to 4 of 4

Thread: Opening Database with code!

  1. #1

    Thread Starter
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344

    Opening Database with code!

    Here is how i am opening it.


    MODULE:

    VB Code:
    1. Option Explicit
    2.  
    3. Global gsMasterDatabasePath As String
    4.  
    5. Global gsMasterConnectionString As String
    6.  
    7. Global Const gsADOProvider = "Microsoft.Jet.OLEDB.4.0"
    8. Public Sub EstablishDataConnections()
    9.  
    10. gsMasterDatabasePath = "C:\Documents and Settings\Ado\My Documents\School\Programming\Final Assignment\Testing\db1.mdb"
    11. gsMasterConnectionString = "Provider= " & gsADOProvider & ";Data Source=" & gsMasterDatabasePath
    12.  
    13. End Sub


    FORM:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim connTEST As ADODB.Connection
    4. Dim rsTEST As ADODB.Recordset
    5.  
    6.  
    7. Private Sub Form_Load()
    8.     Set connTEST = New ADODB.Connection
    9.     Call EstablishDataConnections
    10.     connTEST.Open gsMasterConnectionString
    11.     Set rsTEST = New ADODB.Recordset
    12.     Dim SQL As String
    13.     SQL = "SELECT Main.*, Info.Contents FROM Main Inner Join Info ON Main.CdId = " & _
    14.     "Info.CdId "
    15.    
    16.     rsTEST.Open SQL, connTEST, adOpenStatic, adLockReadOnly, adCmdText
    17.     connTEST.Close
    18.     Set connTEST = Nothing
    19.     Set rsTEST = Nothing
    20.    
    21. End Sub


    Now what i want to do is connect my textbox to the database
    i am trying this but its not working

    txtText.DataSource = rsTest
    txtText.DataField = rsTest!CdId


    I mean basically that wont work, any ideas on how i can connect the textbox to the database?

  2. #2
    Addicted Member Pickler's Avatar
    Join Date
    May 2001
    Location
    nffanb
    Posts
    248
    Use

    VB Code:
    1. Set txtText.DataSource = rsTest
    2. txtText.DataField = "CdId"

    also remove
    connTEST.Close
    and
    Set rsTEST = Nothing
    or else I will not work either.

  3. #3

    Thread Starter
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344
    Thanks alot bro, that worked fine thanks again.

  4. #4
    Lively Member sandin's Avatar
    Join Date
    Nov 2001
    Location
    From Your Heart!!!!
    Posts
    68

    try this!!

    hi...
    There is no need to use the module in this programme.
    just go through with the following code..
    ---------------------
    decularation
    Public connTEST As ADODB.Connection
    Public rsTEST As ADODB.Recordset

    Set connTEST = New Connection
    With connTEST
    .Provider = "Microsoft.Jet.Oledb.4.0"
    .ConnectionString = App.Path & "\Testing\db1.mdb"
    .Open
    End With

    set rsTEST = new adodb.recordset
    rsTEST .Open "select * from assemblymaster", connTEST , adOpenKeyset, adLockOptimistic (e.g.)

    or...
    Dim SQL As String
    SQL = "SELECT Main.*, Info.Contents FROM Main Inner Join Info ON Main.CdId = " & _
    "Info.CdId "


    now check the BOF and EOF
    i.e.
    if EOF and BOf = true then
    txtText.text = rsTEST! fieldname(i.e. which field U want to assign)
    end if

    in this way u can assign the recordset field to the textbox....
    for navigation use the move next , move last , previous and next property of the recordset.

    bye
    sandin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width