Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
57 views

SQL Scripts in VB

you can run SQl SCRIPTS IN VB/vb.net

Uploaded by

api-3745046
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
57 views

SQL Scripts in VB

you can run SQl SCRIPTS IN VB/vb.net

Uploaded by

api-3745046
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// 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

You might also like