Tech Support Guy banner

Problem with a 'Delete Confirmation'

1504 Views 1 Reply 2 Participants Last post by  Anne Troy
I have dynamic ASP web site that I'm interfacing to a MS ACCESS dB where I'm performing add, edit and delete functions. With the delete function I'm using a confirmation dialog box and everything appears to work great except it doesn't actually delete the record. Can anyone shed some light on my coding issue?? I've attached my code below:
Thanks is advance
jknouse
==========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Untitled



<%
' The above line is for ADODB Constants
' For more info see "What is Adovbs.inc and Why Do I Need It?"
' @ http://www.asp101.com/articles/john/adovbs/default.asp

Dim DB_CONNECTIONSTRING ' DB connection string

' Basic Access OLE DB connection
DB_CONNECTIONSTRING = "DSN=nbo_ssc;DRIVER={Microsoft Access Driver}"

Dim cnnConnection
Dim rstShowTable
Dim objField
Dim iLooper
Dim iRecordCount
Dim strRecordsToDelete
Dim strSQL
Dim lngRecordsAffected

Const strTableName = "action_log"
Const strPrimaryKeyFieldName = "autoAIID"
CONST strTable2Name = "Action_Log_2"

' Open our connection:
Set cnnConnection = Server.CreateObject("ADODB.Connection")
cnnConnection.Open DB_CONNECTIONSTRING

' First we see if we've got any records to delete.
strRecordsToDelete = Request.Form(strPrimaryKeyFieldName)

' Quick test to make sure all entries are numeric.
Dim arrTest
arrTest = Split(strRecordsToDelete, ", ")
For iLooper = LBound(arrTest) To UBound(arrTest)
If Not IsNumeric(arrTest(iLooper)) Then strRecordsToDelete = ""
Next

If strRecordsToDelete <> "" Then
strSQL = "DELETE FROM " & strTable2Name & " WHERE " & strPrimaryKeyFieldName _
& " IN (" & strRecordsToDelete & ")"
'Response.Write strSQL

cnnConnection.Execute strSQL, lngRecordsAffected, adExecuteNoRecords
Response.Write "

" & lngRecordsAffected & " Record(s) Deleted! (" _
& Request.Form(strPrimaryKeyFieldName) & ")

"
End If

' Next we show the records currently in the table. I'm showing all
' this table's records, but if your table is large you'll want to
' either show a page at a time or run a query to narrow them down
' to a reasonable number.

'
%>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("../../../Database/NBO_SSC.mdb"))

set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT DISTINCT IMDS_Primary FROM Action_Log WHERE Manager='RArcell' ORDER BY IMDS_Primary ASC"
rs.Open sql,conn

name=request.form("IMDS_Primary")

%>

Select Associate's Name
<% do until rs.EOF
response.write("<option")
if rs.fields("IMDS_Primary")=name then
response.write(" selected")
end if
response.write(">")
response.write(rs.fields("IMDS_Primary"))
rs.MoveNext
loop
rs.Close
set rs=Nothing %>

<%
if name<>"" then
sql="SELECT IMDS_Primary, AIID, Priority, Description, Notes, Open_Date, AutoAIid FROM Action_Log WHERE IMDS_Primary='" & name & "' ORDER BY IMDS_Primary ASC, Type ASC, SortOrder ASC"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn
%>
<%Function IIf(bArg,sTrue,sFalse)
If bArg = True Then IIF = sTrue
If bArg = False Then IIF = sFalse
End Function%>

<%

strSQL = "SELECT IMDS_Primary, AIID, Priority, Description, Notes, Open_Date, AutoAIid FROM Action_Log WHERE IMDS_Primary='" & name & "' ORDER BY IMDS_Primary ASC, Type ASC, SortOrder ASC"

Set rstShowTable = Server.CreateObject("ADODB.Recordset")
rstShowTable.Open strSQL, cnnConnection, adOpenStatic, adLockPessimistic, adCmdText

' Write out title row
Response.Write "
" & objField.Name & "Delete?
" & rstShowTable.Fields(iLooper).Value _
& "
"
Response.Write ""
Response.Write "
[/TH]" & vbCrLf
Next
Response.Write vbTab & vbTab & "[TD]
" & vbCrLf
Response.Write vbTab & " " & vbCrLf
For Each objField in rstShowTable.Fields
Response.Write vbTab & vbTab & " " & vbCrLf
Next
' Extra column for delete checkboxes
Response.Write vbTab & vbTab & " " & vbCrLf
Response.Write vbTab & " " & vbCrLf

If Not rstShowTable.EOF Then
rstShowTable.MoveFirst
' Show data
Do While Not rstShowTable.EOF
Response.Write vbTab & " " & vbCrLf

For iLooper = 0 To rstShowTable.Fields.Count - 1
Response.Write vbTab & vbTab & " " & vbCrLf
Next

' Add checkbox making value the primary key field
Response.Write vbTab & vbTab & " " & vbCrLf

Response.Write vbTab & " " & vbCrLf

rstShowTable.MoveNext
Loop
End If %>
" method="post"
onsubmit="return(confirm('Do you really want to delete the selected records?'));">
<% ' Add row for submit button
Response.Write vbTab & " " & vbCrLf
For Each objField in rstShowTable.Fields
Response.Write vbTab & vbTab & " " & vbCrLf
Response.Write vbTab & " " & vbCrLf

Response.Write "
" & vbCrLf %>

<% ' Get a recordcount so we know if we need to add more records later.
iRecordCount = rstShowTable.RecordCount
'Response.Write iRecordCount

rstShowTable.Close
Set rstShowTable = Nothing

cnnConnection.Close
Set cnnConnection = Nothing
%>
<% end if %>
See less See more
Status
Not open for further replies.
1 - 2 of 2 Posts
Moved to developer's from Business apps.... :)
1 - 2 of 2 Posts
Status
Not open for further replies.
Top