Upload File to SQL Server

liunx

Guest
I want to be able to upload the contents of a text file to sql server via an asp page. Here is what I tried to do (something similar worked in vb) but it didn't work. The issue was the line that said "Open fname For Binary As #1"


fname = "C:\FileToUpload.txt"

Open fname For Binary As #1 'or use FreeFile and a variable to get a file ID# if you prefer
FileContents = Space$(LOF(1)) 'reserve enough space to hold the whole file
Get #1, , FileContents 'read the file into the string
Close #1

Lines = Split(FileContents, vbCrLf) 'split the string into Lines
ReDim UploadArray(1, UBound(Lines)) 'now you know how many rows you have

For i = 0 To UBound(Lines)
Fields = Split(Lines(i), vbTab) ' Split out the fields in each line

For j = 0 To 1
UploadArray(j, i) = Trim(Fields(j))
Next
Next

'now enter these participants
For i = 0 To UBound(UploadArray, 2)
sql = "INSERT INTO Emailer (Recipient, Email, Subject, Message, WhenSent) VALUES ('"
sql = sql & UploadArray(0, i) & "', '" & UploadArray(1, i) & "', 'Running Site Sponsorship Request', 'standard message', '"
sql = sql & Now() & "')"
Set rs = conn.Execute(sql)
Set rs = Nothing
End If


Help modifying that would be much appreciated.Use Scripting.FileSystemObject to read the contents
 
Back
Top