473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need ASP help on uploading a file and updating the DB

1 New Member
Hi I am a newbie to ASP. I am trying to create a form to upload a file (e.g xls or CSV). this file will contain data to update an existing database on the server. I have no problem creating the upload page. But I am having difficulty in writing the ASP page to read the records from the file and update the DB records. Can anyone provide some code sample? Thanks!
Sep 17 '07 #1
1 1142
jhardman
3,406 Recognized Expert Specialist
Hi I am a newbie to ASP. I am trying to create a form to upload a file (e.g xls or CSV). this file will contain data to update an existing database on the server. I have no problem creating the upload page. But I am having difficulty in writing the ASP page to read the records from the file and update the DB records. Can anyone provide some code sample? Thanks!
I think you have hit on a difficult problem: there really needs to be more than one, possibly three different parts to this script. So you said you can upload just fine. Are you saving this file to the server? Do you have a choice of what file format you are going to upload (for example can you decide to always use .xls files?)? If this is the case it would simplify the code dramatically , probably the best would be to open two different recordsets (let's call "rsXls" the recordset from the uploaded file and "rsAccess" the recordset from the permanent database). Then the code would be something like this:
Expand|Select|Wrap|Line Numbers
  1. rsAccess.open "SELECT * FROM table1", connAccess, adOpenDynamic, adLockOptimistic
  2.  'rsAccess needs special cursor, lock to update
  3. rsXls.open "SELECT * FROM [$sheet1]", conXls 'default parameters OK
  4.  
  5. on error resume next
  6. do until rsXls.eof
  7.    rsAccess.addnew
  8.    for each x in rsAccess.fields
  9.       if rsXls(x) <> "" then
  10.          rsAccess(x) = rsXls(x)
  11.       end if
  12.    next
  13.    rsAccess.update
  14.    rsXls.moveNext
  15. loop
I think you'll need the 'on error' line, I can't remember how to determine if the field is an autonumber (since I generally don't try to update it), and that would definitely cause an error when you try to update.

The only question, then, is how are you going to set the "conn" objects. Those declarations will depend on which file formats you are going to use for the two databases. If the file that is going to be uploaded might have several different formats which you can not specify then the connXls declaration will need to be in some sort of select case statement.

Let me know if this helps.

Jared
Sep 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7814
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
2
1535
by: Velhari | last post by:
Hi all, I developed the following codes to implement the concept of Multiple file Uploading Process. Actually my goal in this implementation is to uploads the files onto the server and i have...
3
1899
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
5
2621
by: chromis | last post by:
Hi, I'm trying to figure out the best method for uploading a number of files along with entering some data into a database using a component containing CRUD methods. I have the following file...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.