This topic is locked

save new data in another table error

11/6/2007 10:49:25 AM
ASPRunnerPro General questions
T
Tim author

Hello,
I am attempting to use the "save new data in another table" event from the "before record updated" area of the Edit page. I have added the code via the wizard thing, then only altered the name of the table, the table's field names, and the form's field names. When I run the form I get the error:
Incorrect syntax near ','.
In the asp error I see that the sql query is:
select * from [dbo].[Email_Org] where [dbo].[Email_Org].[OrgEmailID]=31
Here is the code I'm using:
'** Save new data in another table ****

strSQLSave = "INSERT INTO Tickets (Subject, Request) values ("
strSQLSave = strSQLSave & dict(Subject)

strSQLSave = strSQLSave & ","

strSQLSave = strSQLSave & dict(Body)
strSQLSave = strSQLSave & ")"

dbConnection.Execute strSQLSave
BeforeEdit = True
*****

I'm using AsprunnerPro 5.1.

Thanks,

Tim

S
stealthwifi 11/6/2007

Tim,
I have similar code in one of my projects except mine involves an inner join so it looks a little diffrent, have you tried it like this:
[codebox]strSQLSave = "INSERT INTO Tickets (Subject, Request) values (Subject, Body) where " & where

dbConnection.Execute strSQLSave
BeforeEdit = True[/codebox]
I am assuming "Subject" & "Request" are the field names in the table & "Subject" & "Body" are the filed names for the page you are adding/editing too.

Sergey Kornilov admin 11/6/2007

Tim,
do not forget to add single quotes around text fields in SQL query:

strSQLSave = "INSERT INTO Tickets (Subject, Request) values ("

strSQLSave = strSQLSave & "'" & dict(Subject) & "','" & dict(Body) & "')"

dbConnection.Execute strSQLSave
T
Tim author 11/6/2007

Thanks guys! It was the single quotes. Damn syntax!
Thanks again. I'm new to this app and I'm sure I'll have lot's more questions. I'm loving it so far though!

Tim

T
Tim author 11/7/2007

Wait, now I have a different problem. The code inserts a record, but the values are blank if I use dict(FieldName). If I "hard code" a value instead, it writes to the table fine. Any ideas?
Thanks,

Tim

Sergey Kornilov admin 11/7/2007

Add double quotes around the field name: dict("FieldName")