473,563 Members | 2,556 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 1143
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
7823
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 files via FTP. I'm using ftplib to do it, and for each file I'm using transfercmd("STOR " + myfile) to get the socket, then uploading 4096 bytes at...
2
1541
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 to show the status of each and every file to the end user while uploading. In other words, when the first file is start for uploading, means to...
3
1903
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 work properly. That means the file is not uploaded to the specified location. It always executes the "else" condition in my coding. I think the...
5
2626
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 structure: index.cfm - Controller file - display / - create_update.cfm - Contains form for creating and updating a project com /
0
7658
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7877
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7943
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6238
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5479
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.