Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 4th, 2006, 08:06 AM
xara xara is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Location: South Africa
Posts: 4 xara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 59 sec
Reputation Power: 0
Update field value

Hi,

I am importing a excell data into a table.

Now the problem is that I have a field called year in the Table and the spreadsheet. When I run the code to insert the data from the spreadsheat I get the following error

"Syntax error in INSERT INTO statement."

Now I know that has to do with the year field beacause when I leave the year field out it works.

How do I get past this problem?

The Code:
Code:
<% 

Set ExcelConn = Server.CreateObject("ADODB.Connection")
Set ExcelRS = Server.CreateObject("ADODB.Recordset")
ExcelConn.Provider = "Microsoft.Jet.OLEDB.4.0"
ExcelConn.Properties("Extended Properties").Value = "Excel 8.0"
ExcelConn.Open "vehicles.xls"

'get data from sheet
sSQL = "SELECT * FROM [Sample$]"
set ExcelRS = ExcelConn.Execute(sSQL)

'loop through each record in Excel and write it to access

Set objConnAccess = Server.CreateObject("ADODB.Connection")
src = Server.MapPath("mydb.mdb")
sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & src
objConnAccess.Open  sConnStr

Do until ExcelRS.EOF 
objConnAccess.Execute("INSERT INTO sampletbl (show_on_website,del,display_title,stock_number,ma  nufacturer,year,price,colour,vin,mileage,features)   VALUES ('" & ExcelRS("show_on_website") & "','" & ExcelRS("del") & "','" & ExcelRS("display_title") & "','" & ExcelRS("stock_number") & "','" & ExcelRS("manufacturer") & "','" & ExcelRS("year") & "','" & ExcelRS("price") & "','" & ExcelRS("colour") & "','" & ExcelRS("vin") & "','" & ExcelRS("mileage") & "','" & ExcelRS("features") & "')")




ExcelRS.MoveNext
Loop

ExcelRS.Close
set ExcelRS = NOTHING
'objExcelConn.Close
set ExcelConn = NOTHING
objConnAccess.close
set objConnAccess = NOTHING




%>


I do not have the option of leaving the year field empty!

Is it possible to use the update statement and how?

Thanx!!

Reply With Quote
  #2  
Old September 4th, 2006, 08:10 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 10,841 micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 4 Months 4 Days 9 h 33 m 44 sec
Reputation Power: 1705
try wrapping such fields it in [], like this
Code:
objConnAccess.Execute("INSERT INTO sampletbl (show_on_website,del,display_title,stock_number,ma    nufacturer,[year],[price],colour,vin,mileage,features)   VALUES 
('" & ExcelRS("show_on_website") & "','" & ExcelRS("del") & "','" & ExcelRS("display_title") & "','" & ExcelRS("stock_number") & "','" & ExcelRS("manufacturer") & "','" & ExcelRS("year") & "','" & ExcelRS("price") & "','" & ExcelRS("colour") & "','" & ExcelRS("vin") & "','" & ExcelRS("mileage") & "','" & ExcelRS("features") & "')")

hope it helps
__________________
Laziness is my religion and Sunday is my God

Get the Mantra!

Reply With Quote
  #3  
Old September 4th, 2006, 08:21 AM
xara xara is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Location: South Africa
Posts: 4 xara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 59 sec
Reputation Power: 0
Cool, it worked thanx

Reply With Quote
  #4  
Old September 4th, 2006, 08:27 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 10,841 micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)micky User rank is General 11st Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 4 Months 4 Days 9 h 33 m 44 sec
Reputation Power: 1705
no problem, glad i cud help

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Update field value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT