Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2004, 10:28 AM
Authorized User
 
Join Date: Jul 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default writing to database using .asp

Hi I am trying to write values to a database, but when using the INSERT
keyword, i get this error : Number of query values and destination fields
are not the same. I have reduced my number of query values and destination
fields to just one so they are definitely the same. Anyone got any ideas? the code is as follows:

<%
If Len(Request.Form("Company")) = 0 Then
   Response.Redirect("addError.asp")
Else
   Set Conn = Server.CreateObject("ADODB.Connection")
   Conn.Open "DSN=AppsDB"

   Company = ReplaceQuotes(Request.Form("Company"))
' Division = ReplaceQuotes(Request.Form("Division"))
' Device = ReplaceQuotes(Request.Form("Device"))
' Engineer = ReplaceQuotes(Request.Form("Engineer"))
' MainIssue = ReplaceQuotes(Request.Form("MainIssue"))
' DateReceived = ReplaceQuotes(Request.Form("DateReceived"))

   strSql = "INSERT INTO MainTable VALUES('" & Company & "')"
   ', '" & Division & "', '" & Device & "', '" & Engineer & "', '" & MainIssue & "', '" & DateReceived & "')"
   Conn.Execute(strSql)

   Conn.Close
   Set Conn = Nothing
End If

Function ReplaceQuotes(strValue)
   strValue = Replace(strValue, "'", "''")

   ReplaceQuotes = strValue
End Function
%>


 
Old July 12th, 2004, 10:43 AM
Authorized User
 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi you might need to specify the database fields before the values in the same order, you should find that this works.

code below from one of my asp pages. - the values sourronded by [] are database fields.

EG: strSQL= "INSERT INTO webdirectory ([Date],[Catagory],[Organization],[Information_On],[URL_Address]) VALUES ('" & (date) & "','" & (catagory) & "','" & (organization) & "','" & (information_on) & "','" & (website_url) & "')"

regards WM


William
 
Old July 12th, 2004, 11:09 AM
Authorized User
 
Join Date: Jul 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks William, tried that but it's now giving me the error Data Type mismatch in type criteria ..... any ideas?


 
Old July 12th, 2004, 11:48 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

I think the date format is incorrect.
Request.Form("DateReceived") column.


Om Prakash
 
Old July 13th, 2004, 08:26 AM
Authorized User
 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I agree with Om Prakash - it's something to do with the format of the form/dbase fields. Try removing the date field from the form and then submit the remaining info to the dbase - it's a process of elimination i'm afraid.

William





Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to Database Scripts82 ASP.NET 1.0 and 1.1 Professional 8 September 15th, 2006 07:47 AM
Trouble writing database MDrumm Classic ASP Databases 5 August 4th, 2005 03:27 PM
Writing to Database - Please Help Dwizz VB.NET 2002/2003 Basics 12 May 11th, 2005 08:37 AM
writing to a database charliejamesuk MySQL 1 March 25th, 2004 11:10 AM
Writing to access database from asp.et RaZorCleaN Access 2 October 9th, 2003 01:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.