사용자 도구

사이트 도구


kb:vbscriptado

VB Script ADO

Visual Basic Script를 이용한 ADO 사용

샘플

On Error Resume Next
 
DB_SERVER = "localhost"
DB_DATABASE = "AdventureWorks"
DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=" & _
    DB_SERVER & "; Initial Catalog=" & DB_DATABASE & ";Trusted_Connection=Yes"
 
Set myConn = CreateObject("ADODB.Connection")
Set myRecordset = CreateObject("ADODB.Recordset")
 
myConn.Open = DB_CONNECT_STRING
myRecordset.Open "SELECT AddressID, City FROM Person.Address", myConn
 
Set myResult = myRecordset
myResult.MoveFirst
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.CreateTextFile("C:\test.html", True)
 
file.WriteLine "<html><body><table><tr>"
For Index = 0 To myResult.Fields.Count - 1
    file.WriteLine "<td>" & myResult.Fields.Item(Index).Name & "</td>"
Next
file.WriteLine "</tr>"
 
While (Not myResult.EOF)
    file.WriteLine "<tr>"
    For Index = 0 To myResult.Fields.Count - 1
        file.WriteLine "<td>" & myResult.Fields.Item(Index).Value & "</td>"
    Next
    file.WriteLine "</tr>"
    myResult.MoveNext
Wend
 
file.WriteLine "</body></html>"

링크

kb/vbscriptado.txt · 마지막으로 수정됨: 2014/11/09 20:30 (바깥 편집)