...

View Full Version : Inserting new data into table



SteveH
12-04-2007, 01:22 PM
Hello

I have a simple form here:

http://stevehigham59.7host.com/insert2/addit.asp

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

http://stevehigham59.7host.com/insert2/addShow.asp

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
Response.End
end if

rst.AddNew
rst("Fullname") = Fullname
rst("Sex") = Sex
rst("Country") = Country
rst("Hobbies") = Hobbies
rst("DateofBirth")
rst("IpAddr") = link
rst("Date") = Date
rst.update

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.

Steve

Whatever Jr.
12-04-2007, 01: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

zomby
12-05-2007, 01:44 AM
use 3,3

SteveH
12-05-2007, 11:03 AM
Hello

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.

Steve

Whatever Jr.
12-05-2007, 11:32 AM
Hi,

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

What is the error you're receiving now?

Tom

Spudhead
12-05-2007, 05: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum