View Full Version : Importing to an access db from a text file
Anthony1312002
06-03-2005, 02:56 PM
I recently found this script that can read any text file and display it in your browser in it's original format. What I would like to be able to do is post data from the text file to an access table. Can someone give me a hand. If anything you'll have a really nice script for reading text files.
Script
<% Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' Create a filesystem object
Dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")
' Map the logical path to the physical system path
Dim Filepath
Filepath = Request.QueryString("RecordDate")
if FSO.FileExists(Filepath) Then
' Get a handle to the file
Dim file
set file = FSO.GetFile(Filepath)
' Get some info about the file
Dim FileSize
FileSize = file.Size
Response.Write "<p><b>File: " & Request.QueryString("RecordDate") & " (size " & FileSize &_
" bytes)</b></p><hr>"
Response.Write "<pre>"
' Open the file
Dim TextStream
Set TextStream = file.OpenAsTextStream(ForReading,TristateUseDefault)
' Read the file line by line
Do While Not TextStream.AtEndOfStream
Dim Line
Line = TextStream.readline
' Do something with "Line"
Line = Line & vbCRLF
Response.write Line
Loop
Response.Write "</pre><hr>"
Set TextStream = nothing
Else
Response.Write "<h3><i><font color=red> File " & Filename &_
" does not exist</font></i></h3>"
End If
Set FSO = nothing
%>
miranda
06-04-2005, 07:18 PM
I am not sure what you want to save to the database. The entire textfile in one column? or do you want to break the textfile down and only save certain parts of it? If you want the latter option is this textfile in a certain format like csv?
Anthony1312002
06-09-2005, 03:52 PM
Sorry about not replying sooner. It's actually in regular text format. Here is an example of what it looks like.
"CH" 1 "FUMC" "" 05/18/2005 1134 1134 368 368 31 20 0 0 0 0 9 0 137 0 0 0 0 0 0 2263023.28
"CH" 3 "World Com" "" 05/18/2005 185 185 22 22 5 17 404 4 0 0 4 2 87 0 0 0 0 0 0 57064.34
"CH" 12 "Homeq" "" 05/18/2005 268 268 115 115 37 18 0 0 0 0 6 0 7 0 0 0 0 0 0 247785.92
"CH" 22 "World Com" "" 05/18/2005 4722 4722 784 784 934 1665 1231 125 80 18 52 249 15 0 0 0 0 0 0 6771569.72
"CH" 26 "BTI Stub" "" 05/18/2005 524 524 90 90 40 9 29 19 0 0 5 11 0 0 0 0 0 0 0 345945.05
"CH" 28 "Sprint SubDoc" "" 05/18/2005 0 0 0 0 0 0 1911 0 0 0 0 12 0 0 0 0 0 0 0 663351.26
"CH" 31 "Sprint Nibs" "" 05/18/2005 331 331 15 15 54 134 0 14 0 0 236 7 3 0 0 0 0 0 0 1074553.42
"CH" 40 "Nationwide" "" 05/18/2005 14298 14298 928 928 239 261 0 0 0 0 260 0 42 0 0 0 0 918 0 5379606.38
"CH" 52 "World Omni" "" 05/18/2005 8 8 4 4 12 22 28 0 0 0 2 0 2 0 0 0 0 0 0 23409.62
"CH" 53 "Homeq" "" 05/18/2005 534 534 295 295 88 45 0 0 0 0 6 0 29 0 0 0 0 0 0 732100.32
"CH" 59 "Kemper" "" 05/18/2005 1710 1710 331 331 42 40 0 0 0 0 19 0 3 0 0 0 0 0 0 579875.44
"CH" 64 "Sprint Local (New)" "" 05/18/2005 39297 39297 3883 3883 959 2320 0 21 152 17 623 242 12 0 0 0 0 0 0 3654888.84
"CH" 65 "Allianz Insurance" "" 05/18/2005 118 118 8 8 4 2 0 0 0 0 5 0 0 0 0 0 0 0 0 11680.79
"CH" 66 "Liberty Life Insurance" "" 05/18/2005 3212 3212 604 604 491 987 0 0 0 0 59 0 2 0 0 0 0 0 0 206206.89
"CH" 67 "Sun.com" "" 05/18/2005 10990 10990 1495 1495 490 513 377 53 8 2 80 0 2 0 0 0 0 0 0 1233694.60
"CH" 70 "Heilig Meyers Trust" "" 05/18/2005 0 0 14 14 1 2 15 0 0 0 0 0 0 0 0 0 0 0 0 1307.27
"CH" 71 "Anchor/Sun America" "" 05/18/2005 458 458 24 24 1 2 0 0 0 0 18 0 1 0 0 0 0 0 0 200834.80
"CH" 72 "Carolina Health Care" "" 05/18/2005 582 582 287 287 14 29 32 0 3 1 6 0 0 0 0 0 0 0 0 138876.12
"CH" 74 "Wachovia ICR/PEL" "" 05/18/2005 1455 1455 7157 7157 303 172 435 0 0 0 163 0 14 0 0 0 0 0 0 8995551.95
"CH" 76 "Sprint Mixed" "" 05/18/2005 0 0 0 0 176 392 0 0 0 0 140 0 10 0 0 0 0 0 0 77670.06
"CH" 77 "Brinks Home" "" 05/18/2005 5254 5254 1013 1013 17 12 111 0 4 2 54 43 0 0 0 0 0 0 0 283686.26
"CH" 78 "New Adelphia Cable" "" 05/18/2005 14441 14441 1587 1587 50 63 158 0 5 2 107 43 1 0 0 0 0 0 0 1215750.92
"CH" 81 "United/Reliable Ins" "" 05/18/2005 1935 1935 595 595 97 155 0 0 0 0 106 13 1 0 0 0 0 0 0 106357.69
"CH" 84 "Raleigh/Wake" "2000002231875" 05/18/2005 687 687 84 84 104 486 0 0 0 0 12 8 1 0 0 0 0 0 0 167171.31
"CH" 84 "Raleigh/Wake" "2000002231888" 05/18/2005 2054 2054 115 115 210 870 0 0 0 0 43 19 5 0 0 0 0 0 0 379717.49
"CH" 84 "Raleigh/Wake" "" 05/18/2005 2741 2741 199 199 314 1356 0 0 0 0 55 27 6 0 0 0 0 0 0 546888.80
"CH" 88 "World Omni 88" "" 05/18/2005 3278 3278 1196 1196 157 98 557 97 0 0 52 0 20 0 0 0 0 0 0 2082698.38
"CH" 89 "World Omni 89" "" 05/18/2005 582 582 94 94 53 52 112 16 0 0 20 0 1 0 0 0 0 0 0 340293.85
"CH" 94 "Bombardier" "" 05/18/2005 116 116 64 64 0 0 0 141 0 0 16 0 3 0 0 0 0 0 0 136870.65
"CH" 99 "PSCU" "" 05/18/2005 3616 3616 5932 5932 338 191 499 0 2 1 71 68 3 0 0 0 0 0 0 4058909.66
"CH" 248 "Virginia Natural Gas" "" 05/18/2005 6784 6784 145 145 84 171 43 0 19 6 52 0 0 0 0 0 0 0 0 640463.97
"CH" 304 "Henrico County Real Estate" "" 05/18/2005 41 41 4 4 20 160 0 0 0 0 6 2 0 0 0 0 0 0 0 183952.99
"CH" 375 "City of Chesapeake" "" 05/18/2005 163 163 8 8 70 171 0 0 0 0 9 0 3 0 0 0 0 0 0 66940.27
"CH" 487 "Henrico CO Personal Property" "" 05/18/2005 3814 3814 179 179 174 326 0 0 0 0 11 11 0 0 0 0 0 0 0 495298.22
"CH" 526 "Henrico County Utilities" "" 05/18/2005 1164 1164 89 89 6 3 0 0 0 0 12 0 0 0 0 0 0 0 0 94162.20
"CH" 585 "Chesterfield Taxes" "" 05/18/2005 2305 2305 0 0 1507 4943 0 0 0 0 44 0 0 0 0 0 0 0 0 1459657.17
"CH" 601 "Shenandoah Life - Individual" "" 05/18/2005 534 534 33 33 16 30 0 0 0 0 4 1 0 0 0 0 0 0 0 103256.14
"CH" 602 "Shenandoah Life - Group" "" 05/18/2005 221 221 121 121 37 36 0 0 0 0 28 7 0 0 0 0 0 0 0 218189.31
"CH" 725 "Chesterfield Utilities" "" 05/18/2005 146 146 9 9 165 461 0 0 0 0 3 0 0 0 0 0 0 0 0 123970.55
"CH" 826 "Carolina Healthcare" "" 05/18/2005 914 914 217 217 9 12 0 0 0 0 10 20 0 0 0 0 0 0 0 65967.55
"CH" 827 "Regions Bank" "" 05/18/2005 602 602 207 207 70 55 503 221 3 1 6 0 4 0 0 0 0 0 0 791325.08
"CH" 828 "GlobeCast" "" 05/18/2005 2510 2510 634 634 11 7 0 0 0 0 159 0 245 0 0 0 0 0 0 98958.80
"CH" 841 "Duke Univ HealthCare" "" 05/18/2005 949 949 425 425 0 0 0 113 0 0 64 0 0 0 0 0 0 0 0 264957.65
"CH" 842 "Wellcare" "" 05/18/2005 49 49 20 20 0 0 11 0 0 0 4 0 2 0 0 0 0 0 0 4290.47
"CH" 844 "Forsyth County Tax" "" 05/18/2005 762 762 35 35 46 491 0 0 0 0 2 0 0 0 0 0 0 0 0 147600.22
"CH" 848 "Roanoke Gas" "" 05/18/2005 2434 2434 75 75 109 312 0 0 0 0 13 6 0 0 0 0 0 0 0 485915.17
"CH" 849 "Skytel" "" 05/18/2005 2413 2413 243 243 57 93 403 23 42 13 18 41 95 0 0 0 0 0 0 803360.34
"CH" 851 "Haynes Furniture" "" 05/18/2005 567 567 1727 1727 29 32 0 0 0 0 5 0 0 0 0 0 0 0 0 443738.63
"CH" 852 "CenterOne" "" 05/18/2005 48 48 30 30 0 0 0 0 0 0 6 0 1 0 0 0 0 0 0 33436.83
"CH" 866 "WorldOmni CenterOne" "" 05/18/2005 1951 1951 644 644 46 21 308 145 0 0 27 0 3 0 0 0 0 0 0 1507555.45
"CH" 888 "Sun Com" "" 05/18/2005 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37.69
"CH" 948 "Roanoke Gas Stubs Only" "" 05/18/2005 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 2067.95
I'm trying to break it out by columns. Is there a way I can do this?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.