PDA

Click to See Complete Forum and Search --> : Entering SQL commands


Gimpster
Nov 8th, 1999, 03:46 AM
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
corneslen@hotmail.com
ICQ# 47799046

smalig
Nov 8th, 1999, 04:02 AM
If you DAO you need using Execute method.

------------------
smalig
smalig@hotmail.com
smalig.tripod.com (http://smalig.tripod.com)

Gimpster
Nov 8th, 1999, 04:16 AM
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
corneslen@hotmail.com
ICQ# 47799046

Ghost
Nov 8th, 1999, 04:44 AM
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 ?

Gimpster
Nov 8th, 1999, 04:49 AM
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
corneslen@hotmail.com
ICQ# 47799046

JHausmann
Nov 8th, 1999, 07:26 AM
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'"

Clunietp
Nov 8th, 1999, 11:02 AM
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

Gimpster
Nov 10th, 1999, 04:14 AM
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
corneslen@hotmail.com
ICQ# 47799046

Ghost
Nov 10th, 1999, 04:22 AM
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

Gimpster
Nov 10th, 1999, 04:27 AM
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
corneslen@hotmail.com
ICQ# 47799046