Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Can't insert values into Access, only auto number


Message #1 by "Dan Englander" <danomatic12@e...> on Tue, 25 Feb 2003 14:18:03 -0500
I have a form page that goes to an ASP page that inserts the form data into
an Access database. When I submit the form, I get the response page which
does the insert but when I go back to the database, the only thing that has
been inserted is the auto number ID. 

(However, this does indicate that the insert page is "seeing" the database)

I Can't figure why other values aren't inserting like 'Name', 'Email' etc..

Here is my insert code:

	dim connObj, connStr, sSQL
	set connObj = server.CreateObject ("adodb.connection")


	connStr = "DRIVER=Microsoft Access Driver (*.mdb);" &_
   		 "DefaultDir=" & Request.ServerVariables ("PATH_INFO")& ";"
&_
   		 "DBQ=" & server.MapPath ("ContactDan.mdb")

   	 sSQL = "INSERT INTO ContactMe (Name, Email, State, FindSite,
Comments) 	VALUES (" &_
	    "'" & session("Name") + "', " &_
	    "'" & session("Email") + "', " &_
 	   "'" & session("State") + "', " &_
	"'" & session("FindSite") + "', " &_
  	  "'" & session("Comments") + "')"

	connObj.Open connStr
	connObj.execute (sSQL)
	connObj.Close

Dan

Dan Englander
http://www.danenglander.com/

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

Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Tue, 25 Feb 2003 16:19:48 -0500
For one thing, you are using "+" to concat part of the string, and "&" to
concat another part.  Replace all of your "+" with "&".  If you still have a
problem, try doing a Response.Write on your SQL string to make sure it's
doing what you think it is... it could be that there is no value for those
session variables.

One last thing... if one of those session variables contains a single quote
(apostrophe), then that could mess up your SQL string.  You should be sure
to replace single quotes with 2 single quotes in all of the values that you
add to your SQL string.

Regards,
Peter Foti


> -----Original Message-----
> From: Dan Englander [mailto:danomatic12@e...]
> Sent: Tuesday, February 25, 2003 2:18 PM
> To: ASP Databases
> Subject: [asp_databases] Can't insert values into Access, only auto
> number
> 
> 
> I have a form page that goes to an ASP page that inserts the 
> form data into
> an Access database. When I submit the form, I get the 
> response page which
> does the insert but when I go back to the database, the only 
> thing that has
> been inserted is the auto number ID. 
> 
> (However, this does indicate that the insert page is "seeing" 
> the database)
> 
> I Can't figure why other values aren't inserting like 'Name', 
> 'Email' etc..
> 
> Here is my insert code:
> 
> 	dim connObj, connStr, sSQL
> 	set connObj = server.CreateObject ("adodb.connection")
> 
> 
> 	connStr = "DRIVER=Microsoft Access Driver (*.mdb);" &_
>    		 "DefaultDir=" & Request.ServerVariables 
> ("PATH_INFO")& ";"
> &_
>    		 "DBQ=" & server.MapPath ("ContactDan.mdb")
> 
>    	 sSQL = "INSERT INTO ContactMe (Name, Email, State, FindSite,
> Comments) 	VALUES (" &_
> 	    "'" & session("Name") + "', " &_
> 	    "'" & session("Email") + "', " &_
>  	   "'" & session("State") + "', " &_
> 	"'" & session("FindSite") + "', " &_
>   	  "'" & session("Comments") + "')"
> 
> 	connObj.Open connStr
> 	connObj.execute (sSQL)
> 	connObj.Close
> 
> Dan
> 
> Dan Englander
> http://www.danenglander.com/
> 
> -----------------------------------
> 
> 
> 
Message #3 by "Drew, Ron" <RDrew@B...> on Wed, 26 Feb 2003 13:19:53 -0500
Comment out the lines noted below and run it..this should print your
insert statement.  You may have to do a replace of quotes in Name or
Comments like
sInsert =3D "I'm"
sInsert =3D Replace(sInsert, "'", "''")

This replaces all occurrences of one apostrophe (') with two of them
('')

so now sInsert will be "I''m" and your insert should work.
'...............................
dim connObj, connStr, sSQL
'set connObj =3D server.CreateObject ("adodb.connection")
'connStr =3D "DRIVER=3DMicrosoft Access Driver (*.mdb);" &_
'    "DefaultDir=3D" & Request.ServerVariables ("PATH_INFO")& ";" &_
'    "DBQ=3D" & server.MapPath ("ContactDan.mdb")

 sSQL =3D "INSERT INTO ContactMe &_
              (Name, Email, State, FindSite,Comments) &_
 	VALUES ("' & session("Name") &_
                           '",'"  & session("Email") &_
                           "'','" & session("State")  &_
	               "','"  & session("FindSite") &_
  	               "','"  & session("Comments") &_
                           "')"
Response.write sSQL

'	connObj.Open connStr
'	connObj.execute (sSQL)
'	connObj.Close

-----Original Message-----
From: Dan Englander [mailto:danomatic12@e...]
Sent: Tuesday, February 25, 2003 2:18 PM
To: ASP Databases
Subject: [asp_databases] Can't insert values into Access, only auto
number


I have a form page that goes to an ASP page that inserts the form data
into an Access database. When I submit the form, I get the response page
which does the insert but when I go back to the database, the only thing
that has been inserted is the auto number ID.

(However, this does indicate that the insert page is "seeing" the
database)

I Can't figure why other values aren't inserting like 'Name', 'Email'
etc..

Here is my insert code:

	dim connObj, connStr, sSQL
	set connObj =3D server.CreateObject ("adodb.connection")


	connStr =3D "DRIVER=3DMicrosoft Access Driver (*.mdb);" &_
   		 "DefaultDir=3D" & Request.ServerVariables ("PATH_INFO")&
";" &_
   		 "DBQ=3D" & server.MapPath ("ContactDan.mdb")

   	 sSQL =3D "INSERT INTO ContactMe (Name, Email, State, FindSite,
Comments) 	VALUES (" &_
	    "'" & session("Name") + "', " &_
	    "'" & session("Email") + "', " &_
 	   "'" & session("State") + "', " &_
	"'" & session("FindSite") + "', " &_
  	  "'" & session("Comments") + "')"

	connObj.Open connStr
	connObj.execute (sSQL)
	connObj.Close

Dan

Dan Englander
http://www.danenglander.com/

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



  Return to Index