Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Writing to Two Tables at once
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Writing to Two Tables at once

 Post Reply Post Reply
Author
groq View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote groq Quote  Post ReplyReply Direct Link To This Post Topic: Writing to Two Tables at once
    Posted: 24 September 2003 at 12:33pm

Hello fellow ASPers,

I'm trying to write to table inside an access database that's related by a column. The browser keep returning the following error;

=====================================

Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.

======================================

Heres my code:

<%
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("purchase.mdb")

sql_insert = "insert into tblOne (DateRequest, Site, DateNeeded, PurchaseType, Cost, SalesTax, ShippingHandling, ProgramArea, DescripItem, SubmitBy) values ('" & tblone_DateRequest & "', '" & tblone_Site & "', '" & tblone_DateNeeded & "', '" & tblone_PurchaseType & "', '" & tblone_Cost & "', '" & tblone_SalesTax & "', '" & tblone_ShippingHandling & "', '" & tblone_ProgramArea & "', '" & tblone_DescripItem & "', '" & tblone_SubmitBy & "')"

sql_insert2 = "insert into tblTwo (VendorName, VendorAddress, City, State, Zip) values ('" & tbltwo_VendorName & "', '" & tbltwo_VendorAddress & "', '" & tbltwo_City & "', '" & tbltwo_State & "', '" & tbltwo_Zip & "')"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert
con.Execute sql_insert2

' Done. Close the connection
con.Close
Set con = Nothing
%>

What am I doing wrong?  Any help would be greatly appreciated.

Thank you.

Groq

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 12:45pm

Data mismatch usualy means your trying to put a value into the database of a datatype which the field its going in isnt, for example loading a string into a integer data field.

Ive had a quick look at your code, in the insert statement you put the numeric variables like this:

'" & numericVar & "'

When for numeric ones it should be:

" & numericVar & "

The ' tells it its inserting a string

Back to Top
groq View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote groq Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 1:50pm

okay,

I made the suggested changes to my code but still no cigar, and I'm getting a new error message from the browser:

==============================

Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
=============================

I've double checked the database and all the field types are correct.  Oddly, data was added into the tables.  but the foriegn key of one of the tables didn't update from the primary key of the first table.  What am I doing wrong? Anyone?

thanks,

Groq

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 2:51pm
paste the new insert statement for us to see
Back to Top
groq View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote groq Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 3:02pm

ok, here it is

============

sql_insert = "insert into tblOne (DateRequest, Site, DateNeeded, PurchaseType, Cost, SalesTax, ShippingHandling, ProgramArea, DescripItem, SubmitBy) values ('" & tblone_DateRequest & "', '" & tblone_Site & "', '" & tblone_DateNeeded & "', '" & tblone_PurchaseType & "', " & tblone_Cost & ", " & tblone_SalesTax & ", " & tblone_ShippingHandling & ", '" & tblone_ProgramArea & "', '" & tblone_DescripItem & "', '" & tblone_SubmitBy & "')"

sql_insert2 = "insert into tblTwo (VendorName, VendorAddress, City, State, Zip) values ('" & tbltwo_VendorName & "', '" & tbltwo_VendorAddress & "', '" & tbltwo_City & "', '" & tbltwo_State & "', '" & tbltwo_Zip & "')"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert
con.Execute sql_insert2

==========================

groq

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 3:47pm

Its hard to tell sorry.  go to borgs ASP section, and it shows an alternate method to insert into a database which is easier than a single line SQL query

Back to Top
groq View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote groq Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 4:08pm

Gullanian,

thanks for your help.  Who and what is borg?  Is this a member or website. Can you please provide a link?

Thanks,

Groq

Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 5:04pm
Originally posted by groq groq wrote:

 Who and what is borg? 

A fiercesome deity... red sleep deprived eyes, large caffeine stained incisors... seldom bites children and small furry animals... known to mumble to him/itself.

http://www.webwiz.net/asp/default.asp


Lead me not into temptation... I know the short cut, follow me.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.