I am using ASP to connect to a MS Access 97 mdb using a DNS-less connection. I then query the mdb and concatenate the fields and add delimenters then write to a text file. When I read this from the record set and write to a text file, I am getting erroneous/extra data on the ends of certain fields that does not belong. This causes errors when I read the text file to write to another database. This is my code:
<%on error resume next
Set MyConn = Server.CreateObject("ADODB.Connection"
MdbFilePath = "d:\web\applications_dev\test\test.mdb"
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL = "SELECT TITLE.Name AS ProgramTitle, TITLE.ProgramNo AS ProgramNumber, TITLE.ProgDesc AS ProgramDescription, " & _
" TITLE.Duration AS Duration, TITLE.GradeLevel AS GradeLevel, SERIES.Name AS SeriesName, " & _
" SERIES.Description AS SeriesDescription, SERIES.Number AS Subject " & _
"FROM (SERIES INNER JOIN SERIES_ITEMS ON SERIES.ID = SERIES_ITEMS.SeriesID) " & _
" INNER JOIN TITLE ON SERIES_ITEMS.TitleID = TITLE.ID "&_
"ORDER BY SERIES.Name, TITLE.ProgramNo"
Set RS = MyConn.Execute(SQL)
Const ForWriting = 2 ' Input OutPut mode
Const Create = True
Dim MyFile
Dim FSO ' FileSystemObject
Dim TSO ' TextStreamObject
dim strLine
' Use MapPath function to get the Physical Path of file
MyFile = "d:\web\applications_dev\text_files\textfile.txt"
Set FSO = Server.CreateObject("Scripting.FileSystemObject"
Set TSO = FSO.OpenTextFile(MyFile, ForWriting, Create)
WHILE NOT RS.EOF
strLine = ""
strLine = RS("ProgramTitle"
& "#" & "~" & "#" & RS("ProgramNumber"
& "#" & "~" & "#" & RS("ProgramDescription"
& "#" & "~" & "#" & RS("Duration"
& "#" & "~" & "#" & RS("GradeLevel"
& "#" & "~" & "#" & RS("SeriesName"
& "#" & "~" & "#" & RS("SeriesDescription"
& "#" & "~" & "#" & RS("Subject"
TSO.Writeline strLine
if err.number >0 then
Response.Write err.Description
end if
RS.MoveNext
WEND
if err.number = 0 then
Response.Write "<font color=navy>" & "Text File Written Successfully!" & "</font>"
else
Response.Write "<font color=maroon>" & err.Description & "Error in Writing Text File, Please try again!" & "</font>"
end if
' close TextStreamObject and
' destroy local variables to relase memory
TSO.close
Set TSO = Nothing
Set FSO = Nothing
%>
Does anyone see a problem with this code. Any help you can give me with this problem is greatly appreciated. Thanks
Thanks in Advance!
Greg
<%on error resume next
Set MyConn = Server.CreateObject("ADODB.Connection"
MdbFilePath = "d:\web\applications_dev\test\test.mdb"
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL = "SELECT TITLE.Name AS ProgramTitle, TITLE.ProgramNo AS ProgramNumber, TITLE.ProgDesc AS ProgramDescription, " & _
" TITLE.Duration AS Duration, TITLE.GradeLevel AS GradeLevel, SERIES.Name AS SeriesName, " & _
" SERIES.Description AS SeriesDescription, SERIES.Number AS Subject " & _
"FROM (SERIES INNER JOIN SERIES_ITEMS ON SERIES.ID = SERIES_ITEMS.SeriesID) " & _
" INNER JOIN TITLE ON SERIES_ITEMS.TitleID = TITLE.ID "&_
"ORDER BY SERIES.Name, TITLE.ProgramNo"
Set RS = MyConn.Execute(SQL)
Const ForWriting = 2 ' Input OutPut mode
Const Create = True
Dim MyFile
Dim FSO ' FileSystemObject
Dim TSO ' TextStreamObject
dim strLine
' Use MapPath function to get the Physical Path of file
MyFile = "d:\web\applications_dev\text_files\textfile.txt"
Set FSO = Server.CreateObject("Scripting.FileSystemObject"
Set TSO = FSO.OpenTextFile(MyFile, ForWriting, Create)
WHILE NOT RS.EOF
strLine = ""
strLine = RS("ProgramTitle"
TSO.Writeline strLine
if err.number >0 then
Response.Write err.Description
end if
RS.MoveNext
WEND
if err.number = 0 then
Response.Write "<font color=navy>" & "Text File Written Successfully!" & "</font>"
else
Response.Write "<font color=maroon>" & err.Description & "Error in Writing Text File, Please try again!" & "</font>"
end if
' close TextStreamObject and
' destroy local variables to relase memory
TSO.close
Set TSO = Nothing
Set FSO = Nothing
%>
Does anyone see a problem with this code. Any help you can give me with this problem is greatly appreciated. Thanks
Thanks in Advance!
Greg