|
-
Nov 8th, 1999, 04:46 AM
#1
Thread Starter
Hyperactive Member
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
-
Nov 8th, 1999, 05:02 AM
#2
Addicted Member
If you DAO you need using Execute method.
------------------
smalig
[email protected]
smalig.tripod.com
-
Nov 8th, 1999, 05:16 AM
#3
Thread Starter
Hyperactive Member
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
-
Nov 8th, 1999, 05:44 AM
#4
Junior Member
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 ?
-
Nov 8th, 1999, 05:49 AM
#5
Thread Starter
Hyperactive Member
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
-
Nov 8th, 1999, 08:26 AM
#6
Frenzied Member
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'"
-
Nov 8th, 1999, 12:02 PM
#7
Guru
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
-
Nov 10th, 1999, 05:14 AM
#8
Thread Starter
Hyperactive Member
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
-
Nov 10th, 1999, 05:22 AM
#9
Junior Member
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
-
Nov 10th, 1999, 05:27 AM
#10
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|