Results 1 to 10 of 10

Thread: Entering SQL commands

  1. #1

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

    Post

    What is the proper format for entering SQL commands in VB? I need to add some SQL statements to command buttons, but I don't know the proper format. Thanks.

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

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    If you DAO you need using Execute method.

    ------------------
    smalig
    [email protected]
    smalig.tripod.com

  3. #3

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

    Post

    What do you mean by that, can you give me an example? Also, how do you enter SQL commands using ADO, or just ODBC?

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

  4. #4
    Junior Member
    Join Date
    Oct 1999
    Posts
    31

    Post

    what exactly do you mean my adding SQL Statements to command buttons ? Do you want to execute some sql stmt when the command button is clicked ?

  5. #5

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

    Post

    Yes, that's EXACTLY what I want to be able to do. I'm sure it can be done, I've heard other people talk about using them, but I don't know how to word the SQL statement.

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

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

    Post

    Depends entirely on what you want to do. Here's the basics, there are all kinds of variations on these.

    1) retrieve data

    "Select * from tablename where fieldname='something'"

    2) modify existing data

    "Update tablename set fieldname='something' where fieldname='something'"

    3) add data to table

    "insert into table values ('fld1', 'fld2' ...'lastfld')"

    4) delete data from table

    "delete tablename where fieldname='something'"

  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    I recommend everybody print one of these out and have it by your desk when you need syntax of varying SQL statements
    http://w3.one.net/~jhoffman/sqltut.htm

  8. #8

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

    Post

    Ok, well, I think I understand how to enter them now. My next question is: how do I go about displaying the information once I've queried the database? Just for an example, how would I display a query of:

    SELECT * FROM EMPLOYEE

    Suppose the table has 3 columns:

    emp_lname
    emp_fname
    emp_id

    What code do I need to write in order to be able to display those three columns and all the information in them? Please send me a code sample if you can. Thanks.

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

  9. #9
    Junior Member
    Join Date
    Oct 1999
    Posts
    31

    Post

    What kind of database access method are you planning to use DAO, RDO or ADO ? Lets say you use RDO and assuming that the connection to the database has already been made.

    In the click event of the command button you want to execute the SQL statement, the code will look like :

    Dim SQL as string
    Dim rs as rdoResultset

    SQL = "select fld1,fld2 from employee"

    Set rs = MyrdoConn.OpenResultset(sql)

    While Not rs.eof

    field1=rs("fld1") 'fld1 of the current rec
    field2=rs("fld2")
    rs.movenext 'move to the next record
    Wend

  10. #10

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

    Post

    Well, actually I'm using ADO. But does it make a difference in how the commands are entered once the connection is made? Other than the:

    Dim rs as rdoResultset

    would I need to change any of the code to make it work with ADO? And could you explain the sample you gave, so that I can adapt it to my application? Thank you so much for you help.

    ------------------
    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