Discussion Locked

How to update Access db from ASP Page?

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need to take information from user input on an ASP page and write that info to a table (total of 17 fields) in an Access 2k database. I am using the "Insert Into" method, and I'm attempting to write session variables to fields in the table.
I keep getting the following error: "Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2."
Is there another way to do this, or am I leaving something out? If anyone needs to see the code (it is very small), I'll send it.
Thanks for any help you can give,
John Herndon

5 replies

by nikki96

It's probably your connection statement throwing that up.
Connections are not an easy thing in ASP, honestly. If you are using ODBC, you have to have a DSN configured on the system. Assuming you have that...
Here's some code I have that works.

Set billConn = Server.CreateObject("ADODB.Connection")
Set billRecs = Server.CreateObject("ADODB.Recordset")

billConn.open "DSN=billing"

sqlQuery = "select cost from billTbl"
billRecs.Open sqlQuery, billConn, adOpenStatic

See that 3 paramsare being used for my connection. The query string, the connection object, and a variable that specifies the cursor type. You wouldn't need a cursor for an Insert. I need one for this since it is a query and returns many rows.

Does that help?

Nikki

by madestroitsolutions

Well, most definitely make sure your connection is correct, you can do so by running an sql query against it, just to see if it returns a recordset. Regarding the way you are entering all the information with an SQL INSERT Query, since you have 17 fields, it is so much easier to do it with a recordset. I know this because some of my databases are 50 fields long!, lol, in any event, use a recordset:

Set Rs01 = Server.CreateObject("ADODB.Recordset")
sql = "MyTableName"

Const adOpenKeyset = 1
Const adLockOptimistic = 3
Const adCmdTable = &H0002

Rs01.open sql, Connection, adOpenKeySet, adLockOptimistic, adCmdTable

rs01.addnew
Rs01.fields(0) = MyVariable1
Rs01.fields(1) = MyVariable2
Rs01.fields(2) = MyVariable3
Rs01.fields(3) = MyVariable4
....
......
Rs01.fields(16) = MyVariable17
Rs01.update
Rs01.close
Set Rs01 = nothing

If you need further help, send me an e-mail to:
webmaster@KingsDistributors.com

Include the address of the page where I can see the error.

Good luck!

This discussion is closed to new replies.