Results 1 to 7 of 7

Thread: Help for code from www.planetsourcecode.com

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I got this code from www.planetsourcecode.com and I was wondering exactly where to put it and how to use it, because they weren't very clear.

    Public Sub CONNECTODBC()
    Dim dbname As String
    Dim dataset As String
    Dim User3 As String
    Dim pass As String
    Dim db As Database
    Dim X As String
    User3 = "USERID"
    pass = "PSWD"
    dataset = "YOUR DSN NAME"
    dbname = "DATABASE NAME"
    X = "ODBC;database=" & dbname & ";DSN=" & dataset & ";UID=" & User3 & ";PWD=" & pass
    Set db = OpenDatabase("", False, False, X)
    db.Close
    End Sub

    If you could help me figure out exactly how to use it, or figure out a better way to connect to a SQL server, I would appreciate it.


    ------------------
    Thanks,
    Ryan
    [email protected]
    ICQ# 47799046

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    The code you posted opens a database defined to ODBC (DSN = dataset name, you see these in the odbc control panels). Not very useful, the database is only open as long as the routine is.

  3. #3

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    ok, so how do I go about accessing a database w/o using the Data Control in VB?

    ------------------
    Thanks,
    Ryan
    [email protected]
    ICQ# 47799046

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    What is it you would like to do?

  5. #5

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I would like to be able to access a Sybase SQL database WITHOUT using the ugly looking data control. I want to have different controls for the actual moving around inside the database, so I don't want to use the built-in data control. How do I open a database and access it's contents w/o using the data control?

    ------------------
    Thanks,
    Ryan
    [email protected]
    ICQ# 47799046

  6. #6
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    Fair enough. If you modify your odbc open code so that the database object (db) is global (and move the db.close to the form exit) your database, once you've created the DSN(s), will remain open for the life of the program.

    After you've got the database open, you then use recordsets to do the actual work. Here's some code that gets data based upon a select statement.

    Code:
    Qry = "select * from table where field = '" & form.field1.Text & "' order by sortkey"
    Set Rs = db.OpenRecordset(Qry, dbOpenSnapshot)
    If Rs.EOF = False Then
        Do While Not Rs.EOF
            form.field2.Text = Rs.Fields(0)
            form.field3 = Rs.Fields(1)
    '     [...]
            form.field999.value = CInt(Rs.Fields(999))
            Rs.MoveNext
        Loop
    End If
    Rs.Close
    Depending on the ODBC implementation, you can use pretty much every defined method for recordsets (rs.movefirst, rs.movelast, rs.movenext, rs.moveprevious). You need to make sure you're checking the correct properties, for the type of search you perform.



    [This message has been edited by JHausmann (edited 11-01-1999).]

  7. #7

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Ok, GREAT! I'll give that a try and let you know.

    ------------------
    Thanks,
    Ryan
    [email protected]
    ICQ# 47799046

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