473,673 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in copying MS Excel data to MS SQL via ASP

91 New Member
I have an application which updates record from my excel sheet into the MS SQL server DB. Thefirst line of my excel sheet has the column names of my database table. The problem arises with DATE column in my DB table. while updating I always get this error: "Microsoft VBScript runtime error '800a000d'
Type mismatch: 'FormatDateTime ' ".
.

Following is the code of ASP file, which looks OK to me though.
IS it essential that in my excel sheet, datevalue columns should be categorized as DATE.?

Expand|Select|Wrap|Line Numbers
  1. <% 
  2.  
  3. Set ExcelConn = Server.CreateObject("ADODB.Connection")
  4. Set myConn = Server.CreateObject("ADODB.Connection")
  5.  
  6. myconn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = CreditRegistry; User Id = BPA3; Password=sa"
  7.  
  8.     set rs = server.createobject("adodb.recordset")
  9. Set ExcelRS = Server.CreateObject("ADODB.Recordset")
  10. ExcelConn.Provider = "Microsoft.Jet.OLEDB.4.0"
  11. ExcelConn.Properties("Extended Properties").Value = "Excel 8.0"
  12. ExcelConn.Open "C:\inetpub\wwwroot\CreditRegistry\UpdateInfo.xls"
  13.  
  14. sSQL2 = "SELECT * FROM [CreditInfoUpdate2$]"
  15. set ExcelRS = ExcelConn.Execute(sSQL2)
  16.  
  17. Do until ExcelRS.EOF 
  18.  
  19.  
  20. myConn.Execute("UPDATE CreditInfo Set NameCreditGrantor = '" & ExcelRS("NameCreditGrantor") & "', DateAcctOpened ='" & FormatDateTime(ExcelRS("DateAcctOpened"),1) & "', OrgBal = " & ExcelRS("OrgBal") & ", MonthlyPaymt = " & ExcelRS("MonthlyPaymt") & ", DateLastPaymt = '" & FormatDateTime(ExcelRS("DateLastPaymt"),1) & "', Balance = " & ExcelRS("Balance") & ", CreditbySector = '" & ExcelRS("CreditbySector") & "', MannerofPaymt = '" & ExcelRS("MannerofPaymt") & "', Security = '" & ExcelRS("Security") & "', DescofCollateral = '" & ExcelRS("DescofCollateral") & "', AssetClass = '" & ExcelRS("AssetClass") & "' WHERE ElectNo = '" & ExcelRS("ElectNo") & "' AND id = "& ExcelRS("id") &"" )
  21.  
  22.  
  23. ExcelRS.MoveNext
  24. Loop
  25. Response.Write("<p><span class=inlineblack>Data Successfully updated in the Credit Info Table.</span></p>")
  26.  
  27. ExcelRS.Close
  28. set ExcelRS = NOTHING
  29. ExcelConn.Close
  30. set ExcelConn = NOTHING
  31. myConn.close
  32. set myconn = NOTHING
  33.  
  34. %>
I dont want to use DTS. Your help will be much appreciated. I am really stuck on it for quite a long time now.Thanks.
Sep 15 '08 #1
5 2074
DrBunchman
979 Recognized Expert Contributor
Hi kashif73,

The function FormatDateTime is being passed something other than a date. If you comment out the update and just write the values to the screen what does the date field look like?

Dr B
Sep 15 '08 #2
kashif73
91 New Member
Dr. B,
Thanks for the reply. I did a response.write of the statement. It stucks at record # 4 of my excel sheet. In my excel sheet the date is written like 07/07/2007 & its categorized as DATE. But when I change its category to GENERAL(Format Cell>> Number Tab>> Category>> GENERAL), the date value turns into a number (39270). so i think this number is passed to my statement & thats y error is generated. I am sure this is the problem.
Infact I noticed that few of the date records when their CATEGORY was changed to GENERAL, they turned into flat numbers like quoted above. So this means that these records create problem for my SQL statement. I hope you get my point here.??
If i remove these lines from my excel (with above problem of date turning into numbers), the records are successfully inserted to DB.
How to get over with this problem ??? i have attached my excel file.
many thanks foryour help.
Attached Files
File Type: zip UpdateInfo.zip (9.9 KB, 69 views)
Sep 15 '08 #3
kashif73
91 New Member
Anyone plz? need help on it urgently. Thanks.
Sep 15 '08 #4
jhardman
3,406 Recognized Expert Specialist
Anyone plz? need help on it urgently. Thanks.
When I opened up youjr file, the dates are in the format dd/mm/yyyy (26/09/2003 for example) but my excel program interpreted them as if they were in US standard date format: mm/dd/yyyy (09/26/2003). This is of course wrong and most of the numbers were not valid dates. I would guess that this is the problem you are facing. Try to convert them to a non-ambiguous date format (26-Sep-2003 for example) before passing them to the db - this should solve the problem.

Jared
Sep 15 '08 #5
kashif73
91 New Member
Thanks Jared for the suggestion.I have changed the date format to be as US, once they are retrieved in my excel from DB and henceforth they r inserted back again in the same format as in DB. So this solves the problem. Thanks again.
Sep 16 '08 #6

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

Similar topics

0
2984
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
2
3348
by: Samuele Giovanni Tonon | last post by:
hi, i'm trying to develop a trivial application which random copy files from a directory to another one. i made it using pygtk for the graphical interface, however i find some problem with progressbar and ListStore: basically i need to make pulse the progressbar while i'm copying files and write filenames copied on the ListStore on to the window.
0
2129
by: David Alliet | last post by:
Hello, I'm having a bit of a problem with ASP and Excel. A client has developed his own program, which calculates alot of financial stuff, in excel. I'm doing his websites and he has requested the ability to do the same thing his program does, but through the website. Because his excel program is a dozen worksheets (all packed with endless rows of formulas) long, i thought it'd use excel as backbone of the webprogram (don't worry, the...
1
997
by: Hakan | last post by:
I am regularly downloading an asp web page and what I want to do is to do it automatically The web page consists of one main page and many linked pages to it. Firstly I am selecting the whole page and copying it to an excel worksheet afterwards I click on each (there are many) link on the web page and doing the same process once again (selecting it copying it to excel). The links on the page are on the same column but the number of them...
5
8936
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column headers). I used ODBC in my VB.NET program to read that spreadsheet into a dataset, to make it easy to manipulate. The code I use to read it is as the bottom of this posting.
7
1790
by: Joe | last post by:
I've tracked the performance issue down to a single class. This class derives from CollectionBase and stores a basic value type such as string, int, double, etc... I also store the type itself which you can see I'm using when calling AddValue. I implemented ISerializable and GeteObjectData. Here's what I tried: for (int i = 0; i < this.Count; i++) info.AddValue("item" + i.ToString(), this, typeof(type) );
0
1995
by: MathewJose | last post by:
Hi, I have a DatagridView in windows form.It has got a column which has some names that are populated from master table in database.Now i need to copy a set of data against these names. I tried to populate data to the first column from database and then tried to copy excel sheet data against each name but some exceptions are coming.It says "cannot programmaticaly add rows while using data bind". This is the code that i used for...
1
1685
by: battlestarguy | last post by:
I have been creating a database that keeps track of the number of tools in our shop. To keep the upkeep of this database simple, I have created buttons that will import all the relevent data from Excel sheets they alreay use. With this button, I move through each record in the excel sheet, coping it to a new table (I call that 'tempImport'), which is then used to update the main tool inventory table. The 'tempImport' table that I use when...
7
93660
by: NeverLift | last post by:
This is probably answered elsewhere, but I've searched the Web and VBA for Excel manual, find no answers. I have a VBA-coded macro in an Excel workbook that is to open another existing workbook -- a .xls file, not .csv -- copy data from it, paste that into the original workbook where the macro resides, then close the source workbook. If I use the debugger to step through the macro -- putting a breakpoint at its first executable line, run...
0
8508
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8953
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8652
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8704
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7484
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5727
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2849
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 we have to send another system
3
1851
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.