simple delete driving me crazy

Results 1 to 3 of 3

Thread: simple delete driving me crazy

  1. #1
    Marie Guest

    Default simple delete driving me crazy

    I&#039m trying to delete a record specified by a user, and I&#039m fairly sure that I know the code for that. What&#039s tripping me up is the connection--I&#039m trying to connect to the db the same way as for an insert and I keep getting a message that says: "Too few parameters. Expected 1." The code that causes that message is: RecSet.Open sqlstmt, Conn , 1, 2<BR><BR>Alternatively, if I remove "Conn" from code above, I get this error message: "Operation is not allowed on an object referencing a closed or invalid connection."<BR><BR>Any help would be greatly appreciated--I&#039m using a DSN-less connection on an Access db. Thanks!

  2. #2
    Join Date
    Dec 1969

    Default RE: simple delete driving me crazy

    I just grabbed the below code from one of my pages.<BR><BR>Make sure you do<BR><BR>&#060;!-- #INCLUDE file="" --&#062; [and make sure you upload into same folder. Do a file search on your comp for it. I&#039m sure you have it.]<BR><BR>-------<BR><BR> Set MyConn = Server.CreateObject("ADODB.Connection")<BR> set ors = server.createobject("adodb.recordset")<BR> joe = "E:homeintelgapublic_htmladdpagesgamedescript.mdb" <BR> MdbFilePath = joe<BR> MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";" <BR> ors.Open "tblGameDescription", MyConn, adOpenKeyset, adLockOptimistic<BR> ors.find "Name = &#039" & request.form("Name") & "&#039"<BR> ors.Delete<BR> ors.Requery <BR> ors.Close<BR> Set ors = Nothing<BR> MyConn.Close<BR> Set MyConn = Nothing<BR> response.write "Game deleted."

  3. #3
    Neil Popham Guest

    Default RE: simple delete driving me crazy

    the best way to do this marie is to use an SQL statement - not ADO (.Delete method)<BR><BR>the code below will delete any records where the ID = your variable &#039lngID&#039 (usually this would just be one - if ID is an autonumber). it will record the number of records affected in the variable &#039intRecords&#039 - so you can check that the delete worked ok.<BR><BR>here goes:<BR><BR>&#062; strSQL = "DELETE FROM MyTable WHERE ID = " & lngID<BR>&#062; <BR>&#062; Set objCommand = Server.CreateObject("ADODB.Command")<BR>&#062; objCommand.ActiveConnection = strConnect<BR>&#062; objCommand.CommandText = strSQL<BR>&#062; objCommand.CommandType = adCmdText<BR>&#062; objCommand.Execute intRecords<BR>&#062; Set objCommand = Nothing<BR>&#062; <BR>&#062; Response.Write "&#060;p&#062;" & intRecords & " deleted.&#060;/p&#062;" & vbCrLf<BR><BR>you will obviously most likely have to amend the SQL statement - but it is a very simple format, it&#039s just the WHERE clause that you need to really think about. a few examples:<BR><BR>DELETE FROM People WHERE Surname = &#039Smith&#039<BR>DELETE FROM Cars WHERE EngineSize &#062; 1700 AND Seats = 4<BR><BR><BR>good luck

Posting Permissions

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