1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

deleting

Discussion in 'C#' started by salim, Sep 27, 2006.

  1. #1
    I am trying to delete a specific colum, say ProductID = 30 from table Product_tbl

    now when I use server behaviour to delete, by filtering the recordset it doesn't really delete that particular ID but it goes only the next one in the row, for example:



    I enter 30

    the productID deleted is 29, or 28 or which ever productID it encounter.

    is there anyway to solve this please.

    by using filter, I use both URL and Form variable but none works, can sql solve this?



    please let me know
     
    salim, Sep 27, 2006 IP
  2. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    don't understand what you mean by filtering but the sql would be

    "delete from Product_tbl where productid = 30"
     
    Free Born John, Sep 27, 2006 IP
  3. salim

    salim Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the prodctID can 30, 40, 50, or any I have in my table and I want to specifically choose, I enter it through a form and submit it to be deleted, this is what I mean, the filter thing is because I am using dreamweaver and I am using server behaviour
     
    salim, Sep 27, 2006 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    this is your SQL statement
    so if you pass it via a form then it'll be
     
    ludwig, Sep 27, 2006 IP
  5. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    m_id = request.form("whateverthefieldscalled")
    ssql = "delete from Product_tbl where productid = " & m_id
    conn.execute(ssql)

    obviously you need to create the connection first, the code for all that's just been posted in the thread next to this one
     
    Free Born John, Sep 27, 2006 IP
  6. salim

    salim Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    let's say I have this simple page with some delete, how could I fit it so I could use for my own product table please

    I just need to know where, how and what, I am new in all this and I went a bit far not to go back, cheers
     
    salim, Sep 27, 2006 IP
  7. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #7
    first of all
    you may have it like this also
    next you create the SQL statement then redirect to the deletesupplier.asp file, but you don't pass your SQL statement to it,

    You'd better create the script in deletesupplier.asp and only then redirect back to your page, that'll be easier for you :)
     
    ludwig, Sep 27, 2006 IP
  8. salim

    salim Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    it does make sense....but really to me, I am new to asp coding...could you please elaborate, sorry I am not trying to make you do it for me, but if I had an example or where and how then it would make more sense to me, cheers
     
    salim, Sep 28, 2006 IP
  9. salim

    salim Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    okay, I got it working a bit, here it is what I have, but it display a page with "no records found"
    I am not quite sure but here is the problem now, it sayss "no records found"



    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="Connections/connection1.asp" -->
    <%
    ' *** 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("SCRIPT_NAME"))
    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 = ""
    %>
    <%
    ' *** Delete Record: declare variables

    if (CStr(Request("MM_delete")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

    MM_editConnection = MM_connection1_STRING
    MM_editTable = "Products"
    MM_editColumn = "ProductID"
    MM_recordId = "" + Request.Form("MM_recordId") + ""
    MM_editRedirectUrl = "delproduct.asp"

    ' 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
    %>
    <%
    ' *** Delete Record: construct a sql delete statement and execute it

    If (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "") Then

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

    If (Not MM_abortEdit) Then
    ' execute the delete
    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 Recordsetdel__MMColParam
    Recordsetdel__MMColParam = "-1"
    If (Request.Form("ProductID") <> "") Then
    Recordsetdel__MMColParam = Request.Form("ProductID")
    End If
    %>
    <%
    Dim Recordsetdel
    Dim Recordsetdel_numRows

    Set Recordsetdel = Server.CreateObject("ADODB.Recordset")
    Recordsetdel.ActiveConnection = MM_connection1_STRING
    Recordsetdel.Source = "SELECT ProductID FROM Products WHERE ProductID = " + Replace(Recordsetdel__MMColParam, "'", "''") + ""
    Recordsetdel.CursorType = 0
    Recordsetdel.CursorLocation = 2
    Recordsetdel.LockType = 1
    Recordsetdel.Open()

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

    <body>
    <form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
    <% If Not Recordsetdel.EOF Or Not Recordsetdel.BOF Then %>
    <form name="form1" method="POST" action="<%=MM_editAction%>">

    <input type="text" name="textfield">
    <input type="submit" name="Submit" value="Submit">
    <input type="hidden" name="MM_delete" value="form1">
    <input type="hidden" name="MM_recordId" value="<%= Recordsetdel.Fields.Item("ProductID").Value %>">
    </form>
    <% End If ' end Not Recordsetdel.EOF Or NOT Recordsetdel.BOF %>

    <% If Recordsetdel.EOF And Recordsetdel.BOF Then %>
    No Records Found
    <% End If ' end Recordsetdel.EOF And Recordsetdel.BOF %>

    </body>
    </html>
    <%
    Recordsetdel.Close()
    Set Recordsetdel = Nothing%>
     
    salim, Sep 28, 2006 IP
  10. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #10
    well dude, you are new to ASP but you try too hard scripts for a newcomer :)

    make it simple, in place of
    have it like
    then when you know everything by heart then start coding the way you are trying now
     
    ludwig, Sep 30, 2006 IP