|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Insert into syntax
Can any of you SQL gurus see a problem here? It seems no matter how I change the syntax of the INSERT, I get either a syntax error or expected end of statement error.
Please help this rookie. TIA Tom C PS. this is inserting into an Access DB <% brokerage = Request.form("Brokerage") broker_phone = Request.form("Broker_phone") agent = Request.form("agent") agent_phone = Request.form("agent_phone") agent_cell = Request.form("agent_cell") agent_email = Request.form("agent_email") mris = Request.form("mris") pay_type = Request.form("pay_type") cc_no = Request.form("cc_no") cc_type = Request.form("cc_type") cc_exp = Request.form("cc_exp") cc_ccv = Request.form("ccv") address = Request.form("address") city = Request.form("city") state = Request.form("state") zip = Request.form("zip") level = Request.form("level") cust_provision = Request.form("cust_provision") initial_setup = Request.form("initial_setup") post_color = Request.form("post_color") cust_notes = Request.form("cust_notes") %> <% Set conn = Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "e:\web\selectsignp\htdocs\_database\db1.mdb" conn.execute INSERT INTO Create_acct (brokerage, broker_phone, agent, agent_phone, agent_cell, agent_email, MRIS, pay_type, cc_type, cc_no, cc_exp, cc_ccv, address, city, state, zip, level, cust_provision, initial_setup, post_color, Cust_notes) VALUES ('"&brokerage&"','"&broker_phone&"','"&agent&"','"&agent_phone&"','"&agent_cell&"','"&agent_email&"','"&mris&"','"&pay_type&"','"&cc_type&"','"&cc_no&"','"&cc_exp&"','"&cc_ccv&"','"&address&"','"&city&"','"&state&"','"&zip&"','"&level&"','"&cust_provision&"','"&initial_setup&"','"&post_color&"','"&cust_notes&"') conn.close %> |
|
#2
|
|||
|
|||
|
Provided that all your fields are text data types, I don't think the problem is you Statement, it is the way you are using it.
I believe that you need "around the whole statement" conn.execute "INSERT INTO Create_acct (brokerage, broker_phone, agent, agent_phone, agent_cell, agent_email, MRIS, pay_type, cc_type, cc_no, cc_exp, cc_ccv, address, city, state, zip, level, cust_provision, initial_setup, post_color, Cust_notes) VALUES ('"&brokerage&"','"&broker_phone&"','"&agent&"','"&agent_phone&"','"&agent_cell&"','"&agent_email&"','"&mris&"','"&pay_type&"','"&cc_type&"','"&cc_no&"','"&cc_exp&"','"&cc_ccv&"','"&address&"','"&city&"','"&state&"','"&zip&"','"&level&"','"&cust_provision&"','"&initial_setup&"','"&post_color&"','"&cust_notes&"')" S- |
|
#3
|
|||
|
|||
|
Thanks for your quick reply.
Tried all sorts of quote, parenthesis combinations. Your suggestion returned the following: Microsoft VBScript compilation error '800a0401' Expected end of statement /ssp/register.asp, line 41 conn.execute INSERT INTO Create_acct (brokerage, .... --------------------^ This shouldn't be this troublesome. I have several other pages selecting from DB with no problems. I double checked the field types in the DB and they are in fact all text. Any other suggestions? Tom C |
|
#4
|
||||
|
||||
|
Just a piece of advice that I found very useful.
I would Dim a recordset and an SQL statment, use the recordset variable to equal the SQL statment, THEN execute the rs statement. I found that it's a lot more organized when I review the code. Example: Dim rs, strSQL Set adoConn = Server.CreateObject("ADODB.Connection") sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=db1.mdb" & ";" & _ "Persist Security Info=False" adoConn.Open(sConnection) strSQL = "INSERT INTO Create_acct (brokerage, broker_phone, agent, agent_phone, agent_cell, agent_email, MRIS, pay_type, cc_type, cc_no, cc_exp, cc_ccv, address, city, state, zip, level, cust_provision, initial_setup, post_color, Cust_notes) VALUES ('"&brokerage&"','"&broker_phone&"','"&agent&"','"&agent_phone&"','"&agent_cell&"','"&agent_email&"','"&mris&"','"&pay_type&"','"&cc_type&"','"&cc_no&"','"&cc_exp&"','"&cc_ccv&"','"&address&"','"&city&"','"&state&"','"&zip&"','"&level&"','"&cust_provision&"','"&initial_setup&"','"&post_color&"','"&cust_notes&"')" Set rs = adoConn.Execute(strSQL) //////All of your other code here/////////////// Set rs = nothing adoConn.close Set adoConn = nothing It looks a lot nicer and easy to read, but hey, that's only my opinion... |
|
#5
|
||||
|
||||
|
Quote:
You don't need a recordset when running an insert, update or delete statement, since no records are going to be returned. You only need to use a recordset object when data is going to be returned from the query. it should be Code:
Set conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "e:\web\selectsignp\htdocs\_database\db1.mdb"
conn.execute("INSERT INTO Create_acct (brokerage, broker_phone, agent, agent_phone, agent_cell, agent_email, MRIS, pay_type, cc_type, cc_no, cc_exp, cc_ccv, address, city, state, zip, level, cust_provision, initial_setup, post_color, Cust_notes) VALUES ('"&brokerage&"','"&broker_phone&"','"&agent&"','"&agent_phone&"','"&agent_cell&"','"&agent_email&"','"&mris&"','"&pay_type&"','"&cc_type&"','"&cc_no&"','"&cc_exp&"','"&cc_ccv&"','"&address&"','"&city&"','"&state&"','"&zip&"','"&level&"','"&cust_provision&"','"&initial_setup&"','"&post_color&"','"&cust_notes&"')")
conn.close
or Code:
sql = "INSERT INTO Create_acct (brokerage, broker_phone, agent, agent_phone, agent_cell, agent_email, MRIS, pay_type, cc_type, cc_no, cc_exp, cc_ccv, address, city, state, zip, level, cust_provision, initial_setup, post_color, Cust_notes) VALUES ('"&brokerage&"','"&broker_phone&"','"&agent&"','"&agent_phone&"','"&agent_cell&"','"&agent_email&"','"&mris&"','"&pay_type&"','"&cc_type&"','"&cc_no&"','"&cc_exp&"','"&cc_ccv&"','"&address&"','"&city&"','"&state&"','"&zip&"','"&level&"','"&cust_provision&"','"&initial_setup&"','"&post_color&"','"&cust_notes&"')"
Conn.Execute(sql)
|
|
#6
|
||||
|
||||
|
Well, I was close
![]() |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Insert into syntax |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|