By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,841 Members | 1,675 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,841 IT Pros & Developers. It's quick & easy.

What the hell is wrong with the Update statement!

P: n/a
Writing this for a webpage using ASP. I simply want to update to
fields in an Access 2000 DB:

sqlString = "UPDATE dialup SET password = '" & password & "' ,
username = '" & username & "' WHERE k = " & k
Con.Execute sqlString

Password and username are strings, k is a number.
Whenever I run it I get this error:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected
1.

Now, when I response.write sqlString, it seems fine. All variable are
showing up. I simply can't get past this error message.

What am I missing?

NY
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
3 points...

1. The error you are getting indicates that something in your query is not
resolving to the name of a field in a table. Paste it into a query in the
Access database, try to run it, and see what it asks you for. This should
help you find the problem.
2. When executing a command that returns no records, it's best to say so, or
some errors will not be detectable from VB/VBA. Use the adExecuteNoRecords
option to the Execute method.
3. Inserting text the user types directly into SQL is very dangerous,
especially for a Web app. Instead, you should use parameters. Assuming this
is ADO, the code would be something like this...

sqlString = _
"UPDATE dialup SET password = ?, " & _
"username = ? " & _
"WHERE k = ?"

With New ADODB.Command
Set .ActiveConnection = con
.CommandType = adCmdText
.CommandText = sqlString
.Parameters.Append .CreateParameter( _
"prmPassword", adVarChar, adParamInput, 20, password)
.Parameters.Append .CreateParameter( _
"prmUserName", adVarChar, adParamInput, 20, username)
.Parameters.Append .CreateParameter( _
"prmK", adInteger, adParamInput, , k)
.Execute adExecuteNoRecords
End With

On 18 Feb 2004 08:59:54 -0800, na******@hotmail.com (Natthera) wrote:
Writing this for a webpage using ASP. I simply want to update to
fields in an Access 2000 DB:

sqlString = "UPDATE dialup SET password = '" & password & "' ,
username = '" & username & "' WHERE k = " & k
Con.Execute sqlString

Password and username are strings, k is a number.
Whenever I run it I get this error:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected
1.

Now, when I response.write sqlString, it seems fine. All variable are
showing up. I simply can't get past this error message.

What am I missing?

NY


Nov 12 '05 #2

P: n/a
If you are not using an ADO connection then you should try that:

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; " _
& "DBQ=" & Server.MapPath("\yourmdb.mdb")

make sure you have Mdac2.5 and 2.6 loaded on the machine. Then try
treading data from your mdb first. If you can read the data then you
should be able to write the data

strSql = "Select * From tbl1"
Dim RS
Set RS = conn.Execute(strSql)
Do While Not RS.EOF
Response.Write(RS(0).Value & "<br>")
Loop
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

P: n/a
I had a similar problem a few years ago, with VB6. I found that ADO had
a bug that would prohibit using update without moving the cursor. The
recommended fix was to issue a move 0 method before the update. Of
course, you should be using the latest versions, as the others have
suggested.

Martin Wulfe

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.