Print Page | Close Window

Writing to Two Tables at once

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5951
Printed Date: 28 March 2026 at 5:58pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Writing to Two Tables at once
Posted By: groq
Subject: Writing to Two Tables at once
Date 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



-------------
GROQ



Replies:
Posted By: Gullanian
Date 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



Posted By: groq
Date 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



-------------
GROQ


Posted By: Gullanian
Date Posted: 24 September 2003 at 2:51pm
paste the new insert statement for us to see


Posted By: groq
Date 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



-------------
GROQ


Posted By: Gullanian
Date 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



Posted By: groq
Date 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



-------------
GROQ


Posted By: dpyers
Date 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 - http://www.webwiz.net/asp/default.asp



-------------

Lead me not into temptation... I know the short cut, follow me.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net