Using microsoft access file: .mdb
Main Topics
Browse All TopicsI would like to import a large amount of data into my database on my website by uploading a csv file into the database file, as opposed to inputting each record, one by one.
I have a substantial amount of data in EXCEL, which i exported as .txt file (TAB DELIM).
Now what. I believe i will need:
1. Form page with upload function
2. Process page which takes data from .txt file, and puts into the database file.
*I exported my column names into the .txt file. Which would you recommend: no column names, or column names? My guess is no column names.
------------------------
Sample of .txt file
------------------------
COL1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10 Col11 Col12
Mixed Use NEW YORK OPEN MKT 1.20 6 5200 300000 16000 25 88888888 "TEXT DESCRIPTION"
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
yes DTS can be used for it as well - thats teh best way to go ! but for some reason if u cant use it - then u'll need to create a DSN for ur excel file on ur server
Use ur normal upload utility ... allow the user to upload the xls file.
save it on ur server [create a ODBC DSN to this excel file on the server]
<CFQUERY NAME="Qry_Excel" DATASOURCE="Excel_DSN" DBTYPE="ODBC">
select * from "sheet1$"
</CFQUERY>
<cfloop QUERY="Qry_Excel">
<CFQUERY DATASOURCE="DB_Dsn">
Insert into (field1, field2)
values (
<CFQUERYPARAM CFSQLTYPE="cf_sql_varchar"
<CFQUERYPARAM CFSQLTYPE="cf_sql_varchar"
)
</CFQUERY>
</CFLOOP>
If the fieldnames are same just use import function as given above by Tacobell
Insert into DBTable (Select * from "Sheet1$")
could just read the tab delimited file. this example gives you the upload form and the insert to the database.
<cfif isDefined('form.filename')
<cffile action="upload" destination="#expandPath('
<cffile action="read" file="#expandpath(cffile.S
<cfloop index="record" list="#fileData#" delimiters="#chr(10)##chr(
<cfquery name="qryInsert" datasource="whatever">
INSERT INTO tablename (COL1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12)
VALUES (
<cfqueryparam value="#listgetat(record,1
<cfqueryparam value="#listgetat(record,2
<cfqueryparam value="#listgetat(record,3
<cfqueryparam value="#listgetat(record,4
<cfqueryparam value="#listgetat(record,5
<cfqueryparam value="#listgetat(record,6
<cfqueryparam value="#listgetat(record,7
<cfqueryparam value="#listgetat(record,8
<cfqueryparam value="#listgetat(record,9
<cfqueryparam value="#listgetat(record,1
<cfqueryparam value="#listgetat(record,1
<cfqueryparam value="#listgetat(record,1
)
</cfquery>
</cfloop>
Data inserted into the database!!
<cfelse>
<form name="frmData" method="post" enctype="multipart/form-da
<input type="file" name="filename"><br />
<input type="submit">
</form>
</cfif>
How might my form look like which i used to upload the document? I need to append the data, and the .txt file will need to overwrite the .txt file that is stored on the server.
ex. i upload tabDelim.txt today, on tomorrow, i upload again, the new file needs to overwrite tabDelim.txt (hence only having one file on the server), and appending the data to the .mdb file, as opposed to overwriting the data on the .mdb file.
the form could be as simple as this
<form name="frmData" action="doStuff.cfm" method="post" enctype="multipart/form-da
<input type="file" name="filename"><br />
<input type="submit">
</form>
then on the action page
<cffile action="upload" destination="#expandPath('
just use the code I posted earlier for the insert into the database.
jyokum:
So far i tried what you posted and it works, well sorta. it is puttin the information into the datafile, however, i am running into an error. Any inside? My 12th column is a lengthy column, in which I specified it to be a MEMO field to accept the data.
Error Executing Database Query.
[MERANT][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver]Invalid precision value
The Error Occurred in C:\CFusionMX\wwwroot\Testi
31 : <cfqueryparam value="#listgetat(record,1
32 : )
33 : </cfquery>
34 : </cfloop>
35 : Data inserted into the database!!
--------------------------
SQL INSERT INTO Table (Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12) VALUES ( (param 1) , (param 2) , (param 3) , (param 4) , (param 5) , (param 6) , (param 7) , (param 8) , (param 9) , (param 10) , (param 11) , (param 12) )
DATASOURCE testing
VENDORERRORCODE 98
SQLSTATE HY104
If I understand you correctly you are now doing a SELECT on the ACCESS DB and then import each row while looping over it in CF, correct?
Why don't you use
INSERT INTO yourTable
SELECT
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
You can even make the FROM a Query of a Query
INSERT INTO yourTable
SELECT
FROM myQuery
There is no looping volved
If I understand you correctly you are now doing a SELECT on the ACCESS DB and then import each row while looping over it in CF, correct?
Why don't you use
INSERT INTO yourTable
SELECT
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
You can even make the FROM a Query of a Query
INSERT INTO yourTable
SELECT
FROM myQuery
There is no looping involved
jyokum:
I got it to work. cf_sql_longvarchar is the type i need to use.
Here is another problem. Now when i export the TAB Delimited file, any row in access that contains a comma (in my long text field), Excel puts that column in quotes, which is going to be a problem.
How would i go about getting rid of the quotes while they are being INSERTED into the database?
Tacobell777:
Your tactic seems easy to implement, but what i would like to know is, the code you show above is going to be in my action page? Would i be keeping my upload page the same?
1st Page (Select File Page)
--------------------------
<body>
<form name="frmData" action="uploadAction.cfm" method="post" enctype="multipart/form-da
<input type="file" name="filename"><br>
<input type="submit">
</form>
</body>
2nd Page (Process The Upload)
--------------------------
<cffile action="upload" destination="#expandPath('
<cffile action="rename" destination="#expandPath('
<cfif isDefined('form.filename')
<cffile action="upload" destination="#expandPath('
<cffile action="read" file="#expandpath(cffile.S
<cfloop index="record" list="#fileData#" delimiters="#chr(10)##chr(
<cfquery name="qryInsert" datasource="testing">
INSERT INTO Commercial (Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12)
VALUES (
<cfqueryparam value="#listgetat(record,1
<cfqueryparam value="#listgetat(record,2
<cfqueryparam value="#listgetat(record,3
<cfqueryparam value="#listgetat(record,4
<cfqueryparam value="#listgetat(record,5
<cfqueryparam value="#listgetat(record,6
<cfqueryparam value="#listgetat(record,7
<cfqueryparam value="#listgetat(record,8
<cfqueryparam value="#listgetat(record,9
<cfqueryparam value="#listgetat(record,1
<cfqueryparam value="#listgetat(record,1
<cfqueryparam value="#listgetat(record,1
)
</cfquery>
</cfloop>
Data inserted into the database!!
<cfelse>
<form name="frmData" method="post" enctype="multipart/form-da
<input type="file" name="filename"><br>
<input type="submit">
</form>
</cfif>
<cfif isDefined('form.filename')
<cffile action="upload" destination="#expandPath('
<cfquery name="qryInsert" datasource="testing">
INSERT INTO Commercial (Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12)
SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12
FROM OPENDATASOURCE('Microsoft.
'Data Source=c:\Temp; Extended Properties="Text; HDR=No; FMT=Delimited"')...YOURTEX
</cfquery>
</cfloop>
<cfelse>
I think this comes close to what you need.
In regards to the line:
FROM OPENDATASOURCE('Microsoft.
'Data Source=c:\Temp; Extended Properties="Text; HDR=No; FMT=Delimited"')...YOURTEX
this is supposed to work on another computer that does not have the database file on their local computer. The database file is on my web server. This is all working on the internet. so C:\TEMP; will not work. What would i put in the place?
Also I believe your earlier post in regards the EXCEL file works better as i do not have to do any exporting into CSV which is easier, so i will go with that option.
Tacobell777:
I feel like an idiot over here, but this is not working right. somethings wrong with the FROM clause.
<cfquery name="qryInsert" datasource="testing">
INSERT INTO Commercial (Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12)
SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
</cfquery>
--------------rest of source
<body>
<cffile action="upload" destination="#expandPath('
<cffile action="rename" destination="#expandPath('
<cfif isDefined('form.filename')
<cffile action="upload" destination="#expandPath('
<cfquery name="qryInsert" datasource="testing">
INSERT INTO Commercial (Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12)
SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
</cfquery>
Data inserted into the database!!
<cfelse>
<form name="frmData" method="post" enctype="multipart/form-da
<input type="file" name="filename"><br>
<input type="submit">
</form>
</cfif>
</body>
ok. i will put the full path, but my question is the end of the line
...COMM$
is this the correct syntax? Or are you assuming i know what to write at the end of the line:
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
and in regards to OpenDataSource, is this supposed to be the name of my db?
My SQL is not powerful at all and your post is kinda confusing.
Some helpful posts which i just could not get to work in my fashion
http://www.experts-exchang
http://msdn.microsoft.com/
For the life of my i cannot figure out why knowone has asked or posted the question in plain ENGLISH on the following:
How Do I IMPORT all the USED Columns and Rows from an EXCEL file into my .mdb without creating a DSN on the server.
Hypothetical situation: User have data in excel, would like to upload that data (APPENDING) into their current and existing .mdb file on the webserver, without exporting to CSV or TAB DELIMITED.
If you find a link to answer that exact question (with source code), please post it, especially if it is aimed a people with minimal experience with SQL, ExcelOBJECTS, COLDFUSION or DTS.
Business Accounts
Answer for Membership
by: Tacobell777Posted on 2004-02-08 at 15:51:52ID: 10305777
What db are you using?
'Data Source="c:\temp\taco2.xls" ;Extended properties=Excel 5.0')...Sheet1$
If MS SQL, then use DTS (Data Transformation Services) it is made to perform large imports and it easily imports an excel file with 8000 records into the db within a second.
Otherwise you could do something like
INSERT INTO yourTable
SELECT
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',