Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > import a text file to database

Thread Tools

import a text file to database

Posts: n/a

I am still stick on the text file being imported to database. Can anybody help?

I have just done the csv format files. And then I work on text and DAT formats, but I have problem to import these kinds of formats to MySQL ( and MS SQL)
Please see the attachments, and the text format is changed from DAT format, delimited by tabs or commas. I can't select and insert them into the database.

When I try:
select * from thisfile.txt and then insert these records into a designated table of the database.

the error message is:

Microsoft JET Database Engine error '80040e14'

Syntax error in FROM clause.

/insertfile.asp, line 46

' line 46 is
set rs = conn.execute("select * from thisfile.txt")

Thanks for any idea.


'below is the code of what I am going to do with a text file. Please ignore the typing errors and return lines when I make something changed from the original codes.(see the attachment "code.txt" if here the code messes). If the file is csv (thisfile.csv), it works fine.
'thisfile.txt is a text file, and I am using MySQL

sConnection="driver={MySQL ODBC 3.51 Driver};server=localhost;database=upload;uid=root; "
set conn=server.CreateObject("ADODB.Connection")

constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & myPath & "\;Extended Properties=""text;HDRNo;FMT=Delimited"""
set conn2=server.CreateObject("ADODB.Connection")

file_name = "thisfile.txt"

fileStr="select * from " & file_name

set dRs=conn2.execute(fileStr) 'line 46

' insert the recordset into the database.

do until dRs.eof

insertStr="insert into file (filename "

for i = 1 to dRs.Fields.Count
insertStr=insertStr &", f" & i

insertStr = insertStr &") "
insertStr = insertStr & "values ('"&file_name&"'"

for k = 1 to dRs.Fields.Count
fieldata = dRs(k-1)

insertStr = insertStr &", '" & fieldata & "'"

insertStr = insertStr &") "


dRs.close : set dRs = nothing
conn.Close : set conn=nothing
conn2.Close : set conn2 = nothing

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase Computer Information 0 09-26-2012 09:40 AM
Import data from Excel file or text file into database in ASP.NET program bienwell ASP .Net 2 06-17-2006 03:57 AM
exporting an excel file from database; making changes to excel file and updating the database by importing it back Luis Esteban Valencia ASP .Net 1 01-12-2005 12:28 AM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM