Solved

read a CSV file and update an Access DB using ASP

Posted on 2006-10-26
3
216 Views
Last Modified: 2012-05-05
I have done a ton of database programming using SQL Server, Access and ASP.

I have a new challenge now.

I need to build an ASP script where I read a CSV file, break out the fields and then update my DB using ASP. Has anyone done anything like this before? I'm thinking it is fairly easy maybe using something like the "split" function?

Looking for ideas on how to accomplish this and a small snippet of code if possible.'

Thanks!
0
Comment
Question by:samic400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 17815884
<%
dim oConn, sConnectionString, sSQL
set oConn = Server.CreateObject("ADODB.Connection")
sConnectionString = "Provider=SQLOLEDB.1;Initial Catalog=YourDBName;Data Source=ServerName;User Id=Username;PASSWORD=Password;"
Call oConn.Open(sConnectionString)

sSQL = "bulk insert TheDestinationTable from '\\WhateverPlace\WhateverDir\TheFileName' WITH (DATAFILETYPE = 'char', FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')"

Call oConn.Execute(sSQL)

Call oConn.Close()
Set oConn = Nothing
%>

Just make sure that

\\WhateverPlace\WhateverDir\TheFileName

is either a UNC path accessible to SQL server or a path accessible from SQL server.
0
 
LVL 13

Author Comment

by:samic400
ID: 17815910
Would it be the same for an access DB? that is what I will be updating in this case.

I have to actually read record by record because if a certain record already exists in the DB, then I don't want to write to the table.

I'm guessing that I would need to read the text file, row by row, strip out the commas, if my key field doesn't exist, then write the record.

Do the same until i've read through the entire file.

0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 17816618
No this would not work for MS Access. But if you have a SQL server available, do the above and load the data in SQL server. Then do regular query against SQL server and load the data in MS Aceess. That would be much easier. But if you do want to do it directly agains the text file and MS Access, use this connection string to open an ADO connection to text file and then you could use it as if it were a daatabase table.

sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TheFileFolder\;Extended Properties=""text;HDR=Yes;FMT=Delimited"""

Call oConn.Open(sConnectionString)

sSQL = "select * from TheFileName"

Set oRs = oConn.Execute(sSQL)

While Not oRs.EOF
    sField1 = oRs(0)
    sField2 = oRs(2)
    ...
Wend
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question