Jump to content

Help for code to update SQL table


TheValidator

Recommended Posts

Hi Again,I'm creating a web site and from it I am trying to update an MS SQL datatable (table name=main) from within the ASP code in the webpage. I have the following which isn't working. Can you help?<%Dim cDim rDim aSet c = Server.CreateObject("ADODB.Connection")Set r = Server.CreateObject("ADODB.Recordset")c.Open "DSN=btab;UID=XXX;PWD=XXXX;Database=bsql"Dim protocol, startdate, customerDim da="Insert into bsql.main (protocol, startdate, customer) values(request("protocol"),request("startdate"),request("customer") )"r.Open "main", c, 1, 3r.AddNewr("protocol") = request.form("protocol")r("startdate") = request.form("startdate")r("customer") = request.form("customer")r.Updater.Close%>

Link to comment
Share on other sites

Delete the line where you define the variable a. The syntax isn't correct, and you're not using the variable anyway.
Thanks for a reply. At the risk of sounding really stupid, I'd like to continue to pursue my question.REGARDING THE VARIABLE "A":-- My thinking was to declare the variable "a" so that I could assign it a SQL query. From your syntax comment, is the way I declared it incorrect? I was confident that I could declare a variable by simply saying DIM.-- Was there an issue with the query string itself? I see now that it doesn't get used so I now recognize that problem. Is that all or is there more to this?OTHER ISSUES:once I work out how to emply the query string into the logic, is the rest of the code ok or do you see other issues I need to address?thanks for helping
Link to comment
Share on other sites

The syntax issues with the line where you define a are with the quotes. It is a double-quoted string in which you're using double-quotes. If you want to use the values from the request collection in the query it would look more like this:

a="Insert into bsql.main (protocol, startdate, customer) values('" & request("protocol") & "','" & request("startdate") & "','" & request("customer") & "' )"

The fact that the line had a syntax error would stop the entire script from running at all. Syntax errors are fatal errors, when your code has a syntax error nothing executes. It's going to be more secure to use the recordset object to add the data instead of building the query yourself though.

Link to comment
Share on other sites

The syntax issues with the line where you define a are with the quotes. It is a double-quoted string in which you're using double-quotes. If you want to use the values from the request collection in the query it would look more like this:
a="Insert into bsql.main (protocol, startdate, customer) values('" & request("protocol") & "','" & request("startdate") & "','" & request("customer") & "' )"

The fact that the line had a syntax error would stop the entire script from running at all. Syntax errors are fatal errors, when your code has a syntax error nothing executes. It's going to be more secure to use the recordset object to add the data instead of building the query yourself though.

thanks for a prompt reply.this gives me a focus to work on. I hope that I will solve it on my own but I also hope I can come back with additional questions if necessary.thanks again
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...