Click to See Complete Forum and Search --> : about executing sql in vb
kumaresan_ind
Apr 8th, 2000, 01:18 PM
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
lenin
Apr 9th, 2000, 12:08 AM
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.
zambian
Apr 9th, 2000, 02:01 AM
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
Elias
Apr 9th, 2000, 09:14 AM
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
lphillip
Apr 9th, 2000, 02:20 PM
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)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.