By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,830 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,830 IT Pros & Developers. It's quick & easy.

SQL string can't update database

P: 1
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
Share this Question
Share on Google+
3 Replies


shweta123
Expert 100+
P: 692
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

P: 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

P: 7
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.