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
Printable View
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
If you DAO you need using Execute method.
------------------
smalig
[email protected]
smalig.tripod.com
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
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 ?
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
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'"
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
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
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
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