Solved

read a CSV file and update an Access DB using ASP

Posted on 2006-10-26
3
212 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now