Forums
This topic is locked
Insert excel file into SQL db
Posted 07 Jan 2003 18:29:44
1
has voted
07 Jan 2003 18:29:44 Doug Banville posted:
I want to upload and excel file (or .csv)through asp uploadand then take the values in the excel file and insert them into a table in my MS SQL database. The column headings in the excel file match the column heading in the database table. Anybody know of a tiutorial or sample script? Thanks
Replies
Replied 16 Jan 2003 06:51:27
16 Jan 2003 06:51:27 Dave Blohm replied:
I found the following method while surfing. I haven't tested it, but it looks right.
<%
Dim objConn, objFSO, objTF, myRow
Set objConn = Server.CreateObject("ADODB.Connection"
objConn.Open "myDSN" 'open the existing database
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
SetobjTF = objFSO.OpenTextFile("mydata.csv",ForReading , false) ' open the csv file
do while not objTF.AtEndOfStream
myRow = Split(objTF.Readline, ","
objConn.Execute "INSERT INTO myTableName (col1, col2, col3, col4) VALUES (myRow(0), myRow(1), myRow(2), myRow(3))"
loop
objTf.Close
objConn.Close
Set objTF = Nothing
Set objConn = Nothing
Set objFSO = Nothing
%>
Hope this helps...
Doc
Rangewalk Digital Studios
<%
Dim objConn, objFSO, objTF, myRow
Set objConn = Server.CreateObject("ADODB.Connection"
objConn.Open "myDSN" 'open the existing database
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
SetobjTF = objFSO.OpenTextFile("mydata.csv",ForReading , false) ' open the csv file
do while not objTF.AtEndOfStream
myRow = Split(objTF.Readline, ","
objConn.Execute "INSERT INTO myTableName (col1, col2, col3, col4) VALUES (myRow(0), myRow(1), myRow(2), myRow(3))"
loop
objTf.Close
objConn.Close
Set objTF = Nothing
Set objConn = Nothing
Set objFSO = Nothing
%>
Hope this helps...
Doc
Rangewalk Digital Studios
Replied 16 Jan 2003 14:29:01
16 Jan 2003 14:29:01 Doug Banville replied:
Thanks Doc that should do the trick <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 27 Aug 2006 12:41:44
27 Aug 2006 12:41:44 Jerus King replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Thanks Doc that should do the trick <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Hi doug,
I got a problem with inserting csv to db...my db is already setup on the webhosting, i have csv file from my local db, do u have an idea or codes that csv file will insert to db from the provider?please i need ur help..thanks
Thanks Doc that should do the trick <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Hi doug,
I got a problem with inserting csv to db...my db is already setup on the webhosting, i have csv file from my local db, do u have an idea or codes that csv file will insert to db from the provider?please i need ur help..thanks