SQL Update in javascript

G

Guest

Hi;

I'm trying to update an MS Access database with the following code which is
in a Javascript portion of my code for this page created in FrontPage:

var sqlstr = "UPDATE UserInfo SET
FirstName = document.userForm.FirstName.value,
LastName = document.userForm.LastName.value,
Gender = document.userForm.Gender(item).value,
AgeRange = document.userForm.Age(item).value,
FlyTime = document.userForm.FlyTime(item).value,
City = document.userForm.City.value,
State = document.userForm.State.value"

// Build the connection string
var strConn = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=" + Server.MapPath("D:\OLD D\neam_hist\neam_user_info.mdb");

// Create the connection object
var dbConn = Server.CreateObject("ADODB.Connection")

// Open the Connection
dbConn.Open(strConn);

// Execute query
var rs = dbConn.Execute(sqlStr);


When I hit the submit button to validate the form and execute this SQL
command, I get this :

Unterminated string constant

UserInfo is the only table in neam_user_info.mdb. I'm a little new at trying
to bridge the gap between a form in HTML and an Access database so I'd
appreciate any help.
 
J

John Nurick

I don't speak Javascript, but I suspect the "unterminated string
constant" message is being generated by the absence of a quote mark at
the end of
var sqlstr = "UPDATE UserInfo SET

In other words, I doubt whether Javascript allows multiline string
literals.

Also, I'm pretty sure that syntax like this
FirstName = document.userForm.FirstName.value,
won't interpolate the property values into the SQL statement the way you
seem to expect.

In VBScript you'd have to do something like this:

Dim sqlstr
sqlstr = "UPDATE UserInfo SET " _
& "FirstName='" & document.userform.FirstName.Value & "', " _
& ...

which I'll leave you to translate into Javascript syntax.

Also, don't you need a WHERE clause?
 
G

Gina

Hi ....

like john I think as well that the problem might be the sql ...

maybe you want to try:
Dim first, last, gender .... as String
first = document.userForm.FirstName.value
last = document.userForm.LastName.value
gender = document.userForm.Gender(item).value
....
id ??? in the where clause

guess if you don't put an ID where would sql know which line exactly to
update ?!

var sqlstr = "UPDATE UserInfo SET UserInfo.FirstName = '" & first & "',
UserInfo.LastName = '" & last & "', UserInfo.Gender = '" & gender ..... etc
& "' WHERE (UserInfo.UserID= " & document.userForm.userID & ")"
Strings to be put in 'string' quotes !!

Gina
 
S

Steve Schroeder

Three problems:

1. You're using Javascript
2. You're using Frontpage
3. You're not using ADO.Net

:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top