// how to run sql scripts trough vb
believe it or not i did this using ms vb6 programmer's guide. since a sql
script (.sql file) is just a text file you can open it by dimming out a file
system object and setting a text stream using the opentextfile method.
public sub openadorecordset()
dim sqlconn as adodb.connection
dim ts as textstream
dim textfileobj as filesystemobject
dim txtstr as string
dim rs as new adodb.recordset
set textfileobj = new filesystemobject
set sqlconn = new adodb.connection
set ts = textfileobj.opentextfile("c:\sql_test.sql", forreading)
set rs = new adodb.recordset
sqlconn.open "provider= sqloledb; data source= (local); initial catalog=rcris;
user id= sa; password= ;"
txtstr = ts.readall
rs.open txtstr, sqlconn, adopenforwardonly, adlockreadonly
end sub
the sql file actually contains the following sql string:
select top 200 * from rcris0600_master
where agencyid is not null
which was used to open the record set.
you could just as easily use the txtstr below like this:
sqlconn.execute txtstr
to issue commands on a table.
hope this helped.
tom