Solved

read a CSV file and update an Access DB using ASP

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

626 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