adding a record to a DB

Results 1 to 2 of 2

Thread: adding a record to a DB

  1. #1
    Join Date
    Dec 1969

    Default adding a record to a DB

    i have figured out how to read and print out data in a database, but im confused as to how to add a record. ive read about it but the way im doing it is not working. im SURE im just retarded and am overlooking something stupid.. but who knows.. this is my code that calls the DB<BR><BR>Set dbConn = Server.CreateObject("ADODB.Connection")<BR>dbConn. Open "driver={Microsoft Access Driver (*.mdb)};dbq=c:inetpubDatabasesemployeelist.mdb;"< BR>Set rst = Server.CreateObject("ADODB.Recordset")<BR>rst.Acti veConnection = dbConn<BR>rst.CursorType = 1 &#039;adOpenKeyset<BR>rst.LockType = 3 &#039;adLockOptimistic <BR><BR>the table is called Employees and the values in the parenthesis were passed from the previous page via web page form.. what else do i need besides these 2 things to add a record to the DB? the DB was made in access <BR><BR>SQLQuery = "INSERT INTO Employees VALUES (bar, firstname, lastname, address, city, state, zip, homephone, workphone, faxnum, cellphone, pagernum, email, screenname)"<BR>rst.Open SQLQuery<BR><BR>i know hte DB is in the right place because i can use it for other scripts in the same folder.. This is the error im getting when i try to run the above code:<BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039;80040e10&#039; <BR><BR>[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 14. <BR><BR>/newlayouts/addemp.asp, line 31 <BR><BR><BR>any help would be of GREAT asisstance .. thanks!!<BR>

  2. #2
    Join Date
    Dec 1969

    Default Maybe

    trying addnew first just to get a record in the database first?<BR><BR>&#060;%<BR>dim conn<BR>dim rs<BR>dim strID<BR>dim strconn<BR><BR><BR>strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("employeelist.mdb")<BR><BR>set conn = server.createobject("adodb.connection")<BR>conn.op en strconn<BR><BR>set rs = server.createobject("adodb.recordset")<BR><BR>rs.o pen "employees", conn, 2, 2<BR><BR>rs.addnew<BR>rs("bar") = request("bar") <BR>rs("firstname") = request("firstname")<BR><BR>and so on for all of the fields<BR><BR>rs.update<BR><BR><BR> set rs= nothing<BR> set conn = nothing<BR><BR>%&#062;<BR><BR><BR>The INSERT is a little more complex and probably not worth the effort for just adding a new record. It also eliminates having to do replaces for user entered data like the name O&#039;Brien. Give this a try then move onto INSERT.<BR><BR>

Posting Permissions

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