Results 1 to 5 of 5

Thread: about executing sql in vb

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    1
    i want to know, how to execute a query (sql) in VB using
    DAO and ADO

    example: i want to create a table in access,oracle from
    VB using DAO and ADO

  2. #2
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Executing SQL in VB ( using ADO ) is very simple.

    A good reference is the following:

    http://www.vbonline.com/vb-mag/0002/article/ado.htm

    If you have any more questions let me know.


    Lenin.

  3. #3
    Junior Member
    Join Date
    Feb 2000
    Posts
    18

    Using SQL with DAO

    It goes like this:


    Dim db as database
    Dim rs as recordset
    Dim qdf as querydef
    Dim strDbName as string
    Dim strSQL as string

    strSQL = "select * from employees" 'or watever

    strDbname = "..Path of the Access Database.."

    set db = dbEngine.opendatabase(strDbName)
    set qdf = db.createquerydef("")
    qdf.SQL = strSQL

    rs = qdf.openrecordset(dbOpenSnapshot)

    With rs
    ' Do watever u want with the recordset here
    .movefirst
    .movelast
    msgbox .RecordCount

    End with



    Hemang

  4. #4
    Member
    Join Date
    Oct 1999
    Location
    Snellville, GA, USA
    Posts
    38
    1. Set reference to ActiveX Data Object 2.0
    2. Declare your variable as recordset.
    3. Instantiate your recordset. ie set rst....
    4. Set active connection.
    5. Open

    Dim rst as adodb.recordset
    Dim strSQL as string

    'SQL Statenent here.
    strSQL = "select * from employees"

    'Instantiate
    set rst = new adodb.recordset

    'Set active connection
    rst.activeconnection = CONNECTION_STRING

    'Open
    rst.open strSQL

    'Traverse using methods as necessary.
    with rst
    while not .eof
    .movefirst
    .movelast
    wend
    msgbox .RecordCount
    End with

    PS You can use the dataenvironment to help you build connection strings for you. 1. Add a dataenvironment. Look at the properties of the connection. 2. Choose which type of database you wish to connect to. Pick file if Access DB or Server if SQL Server. 3. Pick database if SQL Server. Click test connection. 4. Hit ok. 5. Connection string will appear in properties of the connection object you just created. Paste into code and remove data environment.

    -Good Luck,
    -Elias Rodriguez

  5. #5
    New Member
    Join Date
    Apr 2000
    Posts
    1
    executing a create table statement could not be easier for Access using DAO

    assuming DB is a valid, open, Database object
    and SqlStr is a valid Sql CREATE TABLE string

    DB.execute SqlStr

    I'm not sure if this would work for Oracle/ADO but I use this for all my SQL action statements (INSERT, DELETE, UPDATE, CREATE)

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