Results 1 to 6 of 6

Thread: Database work in VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    17

    Database work in VB6

    I don't know if this really belongs in the Database forum, but seeing as its using old tech (VB6 & SQL 2000), here goes...

    I need to connect to a SQL 2000 database hosted on a server on our corporate network, preferabbly using a DSN connection. From this database, I need to pull customer address details (query below) based on whatever was entered into the txtQuery textbox when the user clicks the cmdSubmit Command Button.

    The results of this query then need to output to list box lstSearch.

    Query:
    Code:
    SELECT title, initials, full_name, company_name, house, address, city, county, postcode, 
    customer FROM cust WHERE customer = **CONTENTS FROM TXTQUERY TEXTBOX**
    All help appreciated!

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Database work in VB6

    Code:
    "SELECT title, initials, full_name, company_name, house, address, city, county, postcode, 
    customer FROM cust WHERE customer = '" & txtQuery & "' Order By full_name"
    VB Code:
    1. Do Until rs.EOF
    2.   lstSearch.AddItem rs!full_name ' or more
    3.   rs.Movenext
    4. Loop

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    17

    Re: Database work in VB6

    Thanks, but how do I go about setting up a connection string & running the query?


    Here's a little more info - As a web developer, here's what I did in PHP - I was originally doing this project on the web, but the remit changed.

    Code:
    $connection_string = 'DRIVER={SQL Server};SERVER=COSYFEET02;DATABASE=eluciddb_test';
    
    $user = '******';
    $pass = '******';
    
    $connection = odbc_connect( $connection_string, $user, $pass );
    $sqlquery="SELECT top 10 title, initials, full_name, house, address, city, county, postcode, customer, company_name FROM cust ORDER BY NEWID();";
    $process=odbc_exec($connection, $sqlquery);
    Last edited by Optimaximal; Jan 3rd, 2007 at 05:55 AM.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Database work in VB6

    VB Code:
    1. Public conSQL As ADODB.Connection
    2. Public rs As ADODB.Recordset
    3.  
    4.       Set conSQL = New ADODB.Connection
    5.       With conSQL
    6.         .ConnectionTimeout = 30
    7.         .Provider = strProvider  ' strProvider=SQLOLEDB.1
    8.         .CursorLocation = adUseClient
    9.         .ConnectionString = "Server=" & strServer & ";" & "User Id=" _
    10.                             & strUserId & ";" & "Password=" _
    11.                             & pwd & ";" & "Initial Catalog=" & strInitCat ' strServer= yourServer Initial Catalog=yourDatabase
    12.         .Open
    13.         '.Execute "Set Dateformat 'dmy'" ' used in Norway to force date format
    14.       End With

    VB Code:
    1. Set rs = New ADODB.Recordset
    2.   With rs
    3.     .ActiveConnection = conSQL
    4.     .CursorLocation = adUseServer ' adUseClient
    5.     .LockType = adLockReadOnly ' adLockOptimistic
    6.     .CursorType = adOpenForwardOnly ' adOpenDynamic
    7.     .Open sqlTekst ' the above select statement
    8.   End With

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    17

    Re: Database work in VB6

    Good Stuff. One more thing, how do I call the connection from a DSN?

    Is it simply just
    Code:
    Conn.Open "DSN NAME GOES HERE"
    ?

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Database work in VB6

    I sometimes forget and must take the shortcut through Adodc1's 'Use Connection String' to find the syntax:
    Code:
    Provider=MSDASQL.1;Persist Security Info=False;Data Source=(yourODBC)

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