Avatar billede jmc Nybegynder
11. august 2001 - 08:57 Der er 6 kommentarer og
1 løsning

slette record hvis field bliver tomt?

hvordan kan jeg slette en record hvis field bliver redigeret tomt?
Avatar billede erikjacobsen Ekspert
11. august 2001 - 09:03 #1
Tjah, ved at teste på det.... Har du noget kode?
Avatar billede jmc Nybegynder
11. august 2001 - 09:19 #2
Produceret i Dreamweaver Ultradev:


<%@LANGUAGE=\"VBSCRIPT\"%>
<!-- #include file=\"access.asp\" -->
<!--#include file=\"Connections/connection.asp\" -->
<%
\' *** Edit Operations: declare variables

MM_editAction = CStr(Request(\"URL\"))
If (Request.QueryString <> \"\") Then
  MM_editAction = MM_editAction & \"?\" & Request.QueryString
End If

\' boolean to abort record edit
MM_abortEdit = false

\' query string to execute
MM_editQuery = \"\"
%>
<%
\' *** Update Record: set variables

If (CStr(Request(\"MM_update\")) <> \"\" And CStr(Request(\"MM_recordId\")) <> \"\") Then

  MM_editConnection = MM_connection_STRING
  MM_editTable = \"journal\"
  MM_editColumn = \"ID\"
  MM_recordId = \"\" + Request.Form(\"MM_recordId\") + \"\"
  MM_editRedirectUrl = \"vis_journal.asp\"
  MM_fieldsStr  = \"textfield|value|ændret|value\"
  MM_columnsStr = \"JOURNAL|\',none,\'\'|ÆNDRET|#,none,NULL\"

  \' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, \"|\")
  MM_columns = Split(MM_columnsStr, \"|\")
 
  \' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

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

End If
%>
<%
\' *** Update Record: construct a sql update statement and execute it

If (CStr(Request(\"MM_update\")) <> \"\" And CStr(Request(\"MM_recordId\")) <> \"\") Then

  \' create the sql update statement
  MM_editQuery = \"update \" & MM_editTable & \" set \"
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),\",\")
    Delim = MM_typeArray(0)
    If (Delim = \"none\") Then Delim = \"\"
    AltVal = MM_typeArray(1)
    If (AltVal = \"none\") Then AltVal = \"\"
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = \"none\") Then EmptyVal = \"\"
    If (FormVal = \"\") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> \"\") Then
        FormVal = AltVal
      ElseIf (Delim = \"\'\") Then  \' escape quotes
        FormVal = \"\'\" & Replace(FormVal,\"\'\",\"\'\'\") & \"\'\"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_editQuery = MM_editQuery & \",\"
    End If
    MM_editQuery = MM_editQuery & MM_columns(i) & \" = \" & FormVal
  Next
  MM_editQuery = MM_editQuery & \" where \" & MM_editColumn & \" = \" & MM_recordId

  If (Not MM_abortEdit) Then
    \' execute the update
    Set MM_editCmd = Server.CreateObject(\"ADODB.Command\")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> \"\") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim Journal__MMColParam
Journal__MMColParam = \"1\"
if (Request.QueryString(\"ID\") <> \"\") then Journal__MMColParam = Request.QueryString(\"ID\")
%>
<%
set Journal = Server.CreateObject(\"ADODB.Recordset\")
Journal.ActiveConnection = MM_connection_STRING
Journal.Source = \"SELECT * FROM journal WHERE ID = \" + Replace(Journal__MMColParam, \"\'\", \"\'\'\") + \"\"
Journal.CursorType = 0
Journal.CursorLocation = 2
Journal.LockType = 3
Journal.Open()
Journal_numRows = 0
%>
<%
Dim journalnavn__MMColParam
journalnavn__MMColParam = \"1\"
if (Request.QueryString(\"ID\") <> \"\") then journalnavn__MMColParam = Request.QueryString(\"ID\")
%>
<%
set journalnavn = Server.CreateObject(\"ADODB.Recordset\")
journalnavn.ActiveConnection = MM_connection_STRING
journalnavn.Source = \"SELECT * FROM hentjournalnavn WHERE ID = \" + Replace(journalnavn__MMColParam, \"\'\", \"\'\'\") + \"\"
journalnavn.CursorType = 0
journalnavn.CursorLocation = 2
journalnavn.LockType = 3
journalnavn.Open()
journalnavn_numRows = 0
%>
<%
\' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

\' create the list of parameters which should not be maintained
MM_removeList = \"&index=\"
If (MM_paramName <> \"\") Then MM_removeList = MM_removeList & \"&\" & MM_paramName & \"=\"
MM_keepURL=\"\":MM_keepForm=\"\":MM_keepBoth=\"\":MM_keepNone=\"\"

\' add the URL parameters to the MM_keepURL string
For Each Item In Request.QueryString
  NextItem = \"&\" & Item & \"=\"
  If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & NextItem & Server.URLencode(Request.QueryString(Item))
  End If
Next

\' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
  NextItem = \"&\" & Item & \"=\"
  If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
  End If
Next

\' create the Form + URL string and remove the intial \'&\' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
if (MM_keepBoth <> \"\") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL <> \"\")  Then MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm <> \"\") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)

\' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> \"\") Then
    MM_joinChar = \"&\"
  Else
    MM_joinChar = \"\"
  End If
End Function
%>
<html>
<head>
<title>Journal</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<link rel=\"stylesheet\" href=\"css.css\" type=\"text/css\">
</head>
<body bgcolor=\"#FFFFFF\" text=\"#000000\">
<div align=\"center\"><A HREF=\"vis_person.asp?<%= MM_keepNone & MM_joinChar(MM_keepNone) & \"CPRNUMMER=\" & Journal.Fields.Item(\"CPRNUMMER\").Value %>\"><span class=\"overskrifter_sort\"><%=(journalnavn.Fields.Item(\"FORNAVN\").Value)%>&nbsp;<%=(journalnavn.Fields.Item(\"EFTERNAVN\").Value)%>s persondata</span></A><br>
</div>
<form name=\"form1\" method=\"POST\" action=\"vis_person.asp?<%= MM_keepNone & MM_joinChar(MM_keepNone) & \"CPRNUMMER=\" & Journal.Fields.Item(\"CPRNUMMER\").Value %>\">
  <div align=\"center\">
    <textarea name=\"textfield\" cols=\"100\" rows=\"30\" class=\"formfelter\"><%=(Journal.Fields.Item(\"JOURNAL\").Value)%></textarea>
    <input type=\"hidden\" name=\"&aelig;ndret\" value=\"<%=now()%>\">
    <br>
    <input type=\"submit\" name=\"Submit\" value=\"Opdater journal\" class=\"formknap\">
    <input type=\"hidden\" name=\"MM_update\" value=\"true\">
    <input type=\"hidden\" name=\"MM_recordId\" value=\"<%= Journal.Fields.Item(\"ID\").Value %>\">
  </div>
</form>
<div align=\"center\"><br>
</div>
</body>
</html>
<%
Journal.Close()
%>
<%
journalnavn.Close()
%>
Avatar billede erikjacobsen Ekspert
11. august 2001 - 09:21 #3
Ups, da, nej tak, mine nerver holder ikke til at kigge Dreamweaver kode
igennem - beklager. Der kommer nok nogen andre senere på dagen :)
Avatar billede zaknafein Praktikant
11. august 2001 - 14:32 #4
Øv en ordentlig pile of dreaweaver s***

Tror Macromedia deltog i en konkurence og at kunne producere det største antal tegn, der kunne mindst!

Du laver da bare en check på feltet, og hvis det er tomt finder du feltets id.

Ud fra det ID kan du køre en delete SQL!
Avatar billede zaknafein Praktikant
11. august 2001 - 14:34 #5
hvis id = 93

\"delete from t_ninja where fld_id =\"&id

Avatar billede jmc Nybegynder
12. august 2001 - 01:53 #6
Jeg prøver her:

set Journal = Server.CreateObject(\"ADODB.Recordset\")
Journal.ActiveConnection = MM_connection_STRING
Journal.Source = \"SELECT * FROM journal WHERE ID = \" + Replace(Journal__MMColParam, \"\'\", \"\'\'\") + \"\"
Journal.CursorType = 0
Journal.CursorLocation = 2
Journal.LockType = 3
Journal.Open()
Journal_numRows = 0

\'NÆSTE TO LINIER HAR JEG SAT IND!
if journal.Source = \"\" then \"delete from journal where ID = \" + Replace(Journal__MMColParam, \"\'\", \"\'\'\") + \"\"


GIVER FØLGENDE FEJL:
/journal/vis_journal.asp, line 113

if journal.Source = \"\" then \"delete from journal where ID = \" + Replace(Journal__MMColParam, \"\'\", \"\'\'\") + \"\"
----------------------------^

Hvad gør jeg galt?
Avatar billede jmc Nybegynder
03. september 2002 - 19:35 #7
takker for hjælpen.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester