Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Record Question

Status
Not open for further replies.

Bkster

Technical User
Jan 25, 2002
94
US
I have an application that allows a user to cancel a job. I used the delete record behavior. It is working90% of the time. The table that the record is being deleted from is only two columns. Job_ID and Employee_ID. It looks like the problem occurs because only the employee_id is being deleted and not the job_id. This causes a problem when someone goes to sign up for a job because the job_id is the primary key and the user gets an error because duplicate entries are not allowed for the job. Like I said it works fine 90% of the time. I am just having to check the database table daily because the job shows up as available but the end user gets the error when they try and sign up for it. Any ideas?


Thanks

Brian
 
Hi Brian,

Post your code up and I'll see how it fairs against some standard VB code (it is VB and not Java?)

M "There are 3 kinds of people; those that can count and those that can't"
 
Here is the code. Thanks for the help.

<%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;1252&quot;%>
<!--#include file=&quot;Connections/airport.asp&quot; -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables(&quot;SCRIPT_NAME&quot;))
If (Request.QueryString <> &quot;&quot;) Then
MM_editAction = MM_editAction & &quot;?&quot; & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = &quot;&quot;
%>
<%
' *** Delete Record: declare variables

if (CStr(Request(&quot;MM_delete&quot;)) = &quot;form1&quot; And CStr(Request(&quot;MM_recordId&quot;)) <> &quot;&quot;) Then

MM_editConnection = MM_airport_STRING
MM_editTable = &quot;tblsch_signup&quot;
MM_editColumn = &quot;schedule_id&quot;
MM_recordId = &quot;&quot; + Request.Form(&quot;MM_recordId&quot;) + &quot;&quot;
MM_editRedirectUrl = &quot;admin_home.asp&quot;

' append the query string to the redirect URL
If (MM_editRedirectUrl <> &quot;&quot; And Request.QueryString <> &quot;&quot;) Then
If (InStr(1, MM_editRedirectUrl, &quot;?&quot;, vbTextCompare) = 0 And Request.QueryString <> &quot;&quot;) Then
MM_editRedirectUrl = MM_editRedirectUrl & &quot;?&quot; & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & &quot;&&quot; & Request.QueryString
End If
End If

End If
%>
<%
' *** Delete Record: construct a sql delete statement and execute it

If (CStr(Request(&quot;MM_delete&quot;)) <> &quot;&quot; And CStr(Request(&quot;MM_recordId&quot;)) <> &quot;&quot;) Then

' create the sql delete statement
MM_editQuery = &quot;delete from &quot; & MM_editTable & &quot; where &quot; & MM_editColumn & &quot; = &quot; & MM_recordId

If (Not MM_abortEdit) Then
' execute the delete
Set MM_editCmd = Server.CreateObject(&quot;ADODB.Command&quot;)
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> &quot;&quot;) Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim conf__MMColParam
conf__MMColParam = &quot;1&quot;
If (Request.QueryString(&quot;schedule_id&quot;) <> &quot;&quot;) Then
conf__MMColParam = Request.QueryString(&quot;schedule_id&quot;)
End If
%>
<%
Dim conf
Dim conf_numRows

Set conf = Server.CreateObject(&quot;ADODB.Recordset&quot;)
conf.ActiveConnection = MM_airport_STRING
conf.Source = &quot;SELECT * FROM qryassignments WHERE schedule_id = &quot; + Replace(conf__MMColParam, &quot;'&quot;, &quot;''&quot;) + &quot;&quot;
conf.CursorType = 0
conf.CursorLocation = 2
conf.LockType = 1
conf.Open()

conf_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body leftmargin=&quot;0&quot; topmargin=&quot;0&quot;>
<p><strong><font size=&quot;3&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Confirm Cancellation
</font></strong></p>
<form name=&quot;form1&quot; method=&quot;POST&quot; action=&quot;<%=MM_editAction%>&quot;>
<font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>This is to confirm that you
are canceling Officer <%=(conf.Fields.Item(&quot;fname&quot;).Value)%>&nbsp;<%=(conf.Fields.Item(&quot;lname&quot;).Value)%> from Post <%=(conf.Fields.Item(&quot;post&quot;).Value)%> on <%=(conf.Fields.Item(&quot;dates&quot;).Value)%> from <%=(conf.Fields.Item(&quot;times&quot;).Value)%> . If this is correct click the Cancel button.
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Cancel&quot;>
</font>
<input type=&quot;hidden&quot; name=&quot;MM_delete&quot; value=&quot;form1&quot;>
<input type=&quot;hidden&quot; name=&quot;MM_recordId&quot; value=&quot;<%= conf.Fields.Item(&quot;schedule_id&quot;).Value %>&quot;>
</form>
<p>&nbsp;</p>
<p>&nbsp; </p>
</body>
</html>
<%
conf.Close()
Set conf = Nothing
%>
 
Thanks for the reply. I forgot to come and close this out. I had forgot to restrict a page that was behind a password protected page. They were bookmarking that page and the available jobs were showing but no session variable had been establish so it was inserting a blank value into the database. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top