Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to sql table

Status
Not open for further replies.

kokser

Programmer
Sep 25, 2009
90
DK
Coming from this thread, I hve dug around and it doesn't seem possibl to do it through ps, so I decided to go back to vbscript and try to execute the sql file.

I have a script that should work, more or less. But it only connects to the database, without choosing a table to write to.

I don't know if it will actually work if I "choose" a table to write to, maybe some of you guys can help me out :)

Code:
Option Explicit
Dim objFSO, strTextFile, strData, strLine, arrLines, mConnection, filestream

CONST ForReading = 1

strTextFile = "C:\file.sql"

Set objFSO = CreateObject("Scripting.FileSystemObject")

set filestream = objFSO.OpenTextFile(strTextFile,ForReading,false,-1)

Function WriteToDatabase(sUserName)

Set mConnection = CreateObject("ADODB.Connection")
mConnection.Open "Provider=SQLOLEDB.1;Data Source=sqlserver\instance;Initial Catalog=mydb","user","password"

do while not filestream.atendofstream
	strData = filestream.readline
	mConnection.Execute strData
loop

Set mConnection = Nothing

End Function

Any help appreciated! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top