View Full Version : Inserting new data into table

12-04-2007, 02:22 PM

I have a simple form here:


which, when filled in, should add records to this simple table:


But I am getting the following error message:

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/insert2/add.asp, line 11

The script behind add.asp is:

'Create a connection to our database using a fileless dsn
Response.Buffer = true
dim cnn,rst
set cnn = Server.CreateObject("ADODB.Connection")
set rst = Server.CreateObject("ADODB.RecordSet")

cnn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\business\Form.mdb;"
sqltext = "SELECT * FROM Enquiries"
rst.Open sqltext,cnn,7,7

dim Enquiries, Fullname,Sex,Country,Hobbies,DateofBirth,ip,Date

Fullname = Request.Form("Fullname")
Sex = Request.Form("Sex")
Country = Request.Form("Country")
Hobbies = Request.Form("Hobbies")
DateofBirth = Request.Form("DateofBirth")
ip = Request.Form("IpAddr")
Date = Request.Form("Date")

if Fullname = "" then
error = "You have not entered your correct name."
Response.Write error
end if

rst("Fullname") = Fullname
rst("Sex") = Sex
rst("Country") = Country
rst("Hobbies") = Hobbies
rst("IpAddr") = link
rst("Date") = Date

Response.Redirect "addit.asp"

I take it that the number 7 referred to able means the number of fields I have in my db (excluding the ID field)?

Thanks for any help.


Whatever Jr.
12-04-2007, 02:57 PM
Nope, the 7 refer to locktype and cursortype.
for more info, visit http://www.w3schools.com/ado/ado_ref_recordset.asp

HTH, Tom

12-05-2007, 02:44 AM
use 3,3

12-05-2007, 12:03 PM

Thank you for your messages and the link. Way off track, wasn't I?!

I am now using 3,3.

I do have the AddNew property, but I do not have this:

objRecordset.AddNew fieldlist,values.

On the other hand, will this not suffice: set rst = Server.CreateObject("ADODB.RecordSet")?

If not the above, what do you think might be causing the error I am getting?

Any advise would be appreciated.

Thanks again.


Whatever Jr.
12-05-2007, 12:32 PM

the AddNew method can accept 2 arrays: fieldlist, values.

What is the error you're receiving now?


12-05-2007, 06:01 PM
Why use a recordset to do an insert?

cnn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\business\Form.mdb;"
sqltext = "INSERT INTO Enquiries (Fullname, Sex, Country, Hobbies, DateofBirth, IpAddr, Date) VALUES ('& Fullname &', '& Sex &', '& Country &', '& Hobbies &', '& DateofBirth &', '& ip &', '& Date &')"
cnn.Execute sqltext

With the above you can (a) save your server the trouble of creating pointless and heavy objects in memory, and (b) actually see - and debug - the SQL that's getting fired at your database.