Forums
This topic is locked
Update problem
Posted 19 Apr 2006 06:39:33
1
has voted
19 Apr 2006 06:39:33 chong lu yen posted:
<%sql= "Update [Employee] Set FullName='"& FullName & "', Department ='" & Department & "',Balance ='" & Balance &"',Email ='" & Email &"',Username ='" & Username &"',Password ='" & Password &"',Repassword ='" & Repassword &"' WHERE ID= " & ID & ""
Rs.Open sql, Conn
%>
why got "Syntax error in UPDATE statement"? can someone help me??thanx
Replies
Replied 19 Apr 2006 16:59:42
19 Apr 2006 16:59:42 micah santos replied:
<%
sql = "Update [Employee] Set FullName='"& FullName & "', Department ='" & Department & "',Balance ='" & Balance &"',Email ='" & Email &"',Username ='" & Username &"',Password ='" & Password &"',Repassword ='" & Repassword &"' WHERE ID= " & strID
%>
try to make it sure you didn't use any reserved words
www.aspfaq.com/show.asp?id=2080
rename the ID to strID
e.g.
Dim strId
strID = Request.Form("ID"
Suggestion:
make a differences in naming between your fields and variables for them to be identifiable. for that matter, it will be easy for you to debug errors co'z you know if it is a variable or came from the database when it occured.
e.g.
Username = '" & Username & "'
why make it like this:
USERNAME = "& glUsername & "
----------------------
here's another way to update a record. take a note, i've followed your codes, however, i renamed all the variables you used instead.
<%
set commUpdate = Server.CreateObject("ADODB.Command"
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("records.mdb" & ";"
commUpdate.ActiveConnection = strConnect
commUpdate.CommandText = "Update [EMPLOYEE] Set fullname='" & glFullname & "', department='" & glDepartment & "', balance ='" & glBalance & "', email ='" & glEmail & "', username ='" & glUsername & "', [password] ='" & glPassword &"', repassword ='" & glRepassword &"' WHERE ID= " & strID
commUpdate.CommandType = 1
commUpdate.CommandTimeout = 0
commUpdate.Prepared = true
commUpdate.Execute()
%>
sql = "Update [Employee] Set FullName='"& FullName & "', Department ='" & Department & "',Balance ='" & Balance &"',Email ='" & Email &"',Username ='" & Username &"',Password ='" & Password &"',Repassword ='" & Repassword &"' WHERE ID= " & strID
%>
try to make it sure you didn't use any reserved words
www.aspfaq.com/show.asp?id=2080
rename the ID to strID
e.g.
Dim strId
strID = Request.Form("ID"
Suggestion:
make a differences in naming between your fields and variables for them to be identifiable. for that matter, it will be easy for you to debug errors co'z you know if it is a variable or came from the database when it occured.
e.g.
Username = '" & Username & "'
why make it like this:
USERNAME = "& glUsername & "
----------------------
here's another way to update a record. take a note, i've followed your codes, however, i renamed all the variables you used instead.
<%
set commUpdate = Server.CreateObject("ADODB.Command"
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("records.mdb" & ";"
commUpdate.ActiveConnection = strConnect
commUpdate.CommandText = "Update [EMPLOYEE] Set fullname='" & glFullname & "', department='" & glDepartment & "', balance ='" & glBalance & "', email ='" & glEmail & "', username ='" & glUsername & "', [password] ='" & glPassword &"', repassword ='" & glRepassword &"' WHERE ID= " & strID
commUpdate.CommandType = 1
commUpdate.CommandTimeout = 0
commUpdate.Prepared = true
commUpdate.Execute()
%>