472,142 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

SQL string can't update database

G'day,

SQL="INSERT INTO KQPlayers VALUES(" & _
"," & _
"'" & Request.Form("username") & "'," & _
(--snip--)

Conn.Execute SQL

This generates an error because my first field in the table (line 2 in the sql statement) is an AutoNumber and I don't know how to skip adding values to that field.

The above code gives me
Syntax error in INSERT INTO statement.

If I put a 0 in the first field before the comma I get ...
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

Just to test it, I tried ...
Sql="insert into Players (username) values('" & Request.Form("username") & "'" )
I get

Error: Missing Fields
You must enter all fields to proceed.
Dec 9 '06 #1
3 1803
shweta123
692 Expert 512MB
Give sql like this

SQL="INSERT INTO KQPlayers VALUES(
"'" & Request.Form("username") & "'," & _
(--snip--)

don't put anything for the autonumber field.

Shweta
Dec 12 '06 #2
gyung
21
I have another field, cID which is a Primary Key AUTO_NUMBER. I skip it and the DB takes care of it.

Expand|Select|Wrap|Line Numbers
  1. SQL = "INSERT INTO class (cName,cShow) VALUES('"
  2.             SQL = SQL & cName & "','" & cShow & "');"
  3.             'response.Write(sql)
  4.             'response.End()
  5.             'Open connection
  6.             'objConn.open
  7.             objConn.Execute SQL
  8.  
  9.             closeConn()
Dec 12 '06 #3
I have another field, cID which is a Primary Key AUTO_NUMBER. I skip it and the DB takes care of it.

Expand|Select|Wrap|Line Numbers
  1. SQL = "INSERT INTO class (cName,cShow) VALUES('"
  2.             SQL = SQL & cName & "','" & cShow & "');"
  3.             'response.Write(sql)
  4.             'response.End()
  5.             'Open connection
  6.             'objConn.open
  7.             objConn.Execute SQL
  8.  
  9.             closeConn()
if cID is sequential field defined by DBMS, i think u shouldn't type it in INSERT query. If i was you I would do this

"INSERT INTO class (cShow) VALUES("& _
" ' "& cShow & "');"
'response.Write(sql)
'response.End()
'Open connection
'objConn.open
objConn.Execute SQL

closeConn()

I think that'll work properly
Dec 12 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Qwiati | last post: by
5 posts views Thread by Fred Zuckerman | last post: by
5 posts views Thread by bardo | last post: by
6 posts views Thread by Manuel Canas | last post: by
reply views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
5 posts views Thread by andrei.avk | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.