Avatar billede jmc Nybegynder
18. juni 2001 - 19:43 Der er 4 kommentarer og
2 løsninger

hvordan slettes en tom record!

Det handler om en record som der kan fyldes tekst ind i via et textfield! Hvis man sletter alt tekst i tekstfieldet skal hele den pågældende record også slettes. Hvordan gør jeg dette?
Avatar billede stigc Nybegynder
18. juni 2001 - 19:44 #1
where textvalue=\'\'
Avatar billede jmc Nybegynder
18. juni 2001 - 19:53 #2
Har du en ide om hvor jeg skulle skrive [where textvalue=\'\'] i denne kode?

<%
\' *** 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
%>
Avatar billede icedox Nybegynder
18. juni 2001 - 20:12 #3
sql = \"delete * from tabel where ID=\'\" & detderskalslettes & \"\'\"
conn.execute (sql)

Er det sql du mangler ?
Textvalue, er det den der indholder din notat?
Avatar billede s_raagaard Nybegynder
18. juni 2001 - 22:15 #4
Hvis textfeltet er tomt slettes record fra db, ellers opdateres den med det nye indhold:

<%
if request(\"TextField\")=\"\" then

RecordID = Replace(Request.form(\"RecordID\"), \"\'\", \"\'\'\")
TextField= Replace(Request.form(\"TextField\"), \"\'\", \"\'\'\") 
strSQL = \"DELETE DISTINCTROW RecordID \"
strSQL = strSQL & \"FROM TrecordsTable \"
strSQL = strSQL & \"WHERE RecordID= \" & RecordID
Set rs = myConn.Execute(strSagSQL)

else

RecordID = Replace(Request.form(\"RecordID\"), \"\'\", \"\'\'\")
TextField= Replace(Request.form(\"TextField\"), \"\'\", \"\'\'\") 
strSQL = \"UPDATE DISTINCTROW TrecordsTable \"
strSQL = strSQL & \"SET TextField=\'\" & TextField & \"\' \"
strSQL = strSQL & \"WHERE RecordID=\" & RecordID
Set rs = myConn.Execute(strSQL)

end if
%>


/søren
Avatar billede icedox Nybegynder
20. juni 2001 - 19:48 #5
Det lyder ikke så fornuftigt at SLETTE et tomt felt!
Men, hvad med :
sql =\"Update table set bla bla
så skal den kun opdateres.
Hallo!
J.
Avatar billede jmc Nybegynder
19. august 2001 - 19:04 #6
Tak, for hjælpen. Jeg tror jeg prøver s_raagaard 
svaret - det ser fornuftigt ud! Hvorfor bevare et tomt felt som aldrig skal bruges mere!
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