Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Inserting new data into table

    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

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Posts
    120
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Nope, the 7 refer to locktype and cursortype.
    for more info, visit http://www.w3schools.com/ado/ado_ref_recordset.asp

    HTH, Tom

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use 3,3

  • #4
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    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

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Posts
    120
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Hi,

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

    What is the error you're receiving now?

    Tom

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Why use a recordset to do an insert?

    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •