delete command doesn't work as I want

Discussion in 'ASP .Net' started by xan, Apr 26, 2004.

  1. xan

    xan Guest

    Here is want I and writting. It works, but it delete another record not the
    only where I click the command delete button.

    What I'm doing wrong?

    ' -------------------------------------------------------------------------
    Sub dgDatos_Delete(obj As object, e As DataGridCommandEventArgs)
    Dim strSQL As String = "DELETE FROM datos " & _
    "WHERE numero = " & e.Item.ItemIndex & ";"

    ExecuteStatement(strSQL)

    LlenarDatosDeCuadricula()
    lblMensaje.Text = lblMensaje.Text & e.Item.cells(0).Text
    End Sub
    ' ----------------------------------------------------------------------
    function ExecuteStatement(strSQL)
    Dim objCmd As New OleDbCommand(strSQL, Conn)

    try
    objCmd.Connection.Open()
    lblmensaje2.text=""
    objCmd.ExecuteNonQuery()
    catch ex As Exception
    lblMensaje.Text = "consulta:<br>" & strSQL & "<br>Error al
    actualizar la base de datos.<br> " & ex.tostring()
    End try

    objCmd.Connection.Close()
    End function
    ' --------------------------------------------------------------------------
     
    xan, Apr 26, 2004
    #1
    1. Advertisements

  2. xan

    Rick Spiewak Guest

    Use e.item.datasetindex to find the correct offset into the database. But,
    this may not always correspond to the "numero" field. You may want to use
    this index to locate the record in your datasource (the row in a dataset,
    for example), and use one or more of the fields from that record to
    construct your delete command to be sure that you get the correct record.

    "xan" <> wrote in message
    news:efwkr%...
    > Here is want I and writting. It works, but it delete another record not

    the
    > only where I click the command delete button.
    >
    > What I'm doing wrong?
    >
    >

    ' -------------------------------------------------------------------------
    > Sub dgDatos_Delete(obj As object, e As DataGridCommandEventArgs)
    > Dim strSQL As String = "DELETE FROM datos " & _
    > "WHERE numero = " & e.Item.ItemIndex & ";"
    >
    > ExecuteStatement(strSQL)
    >
    > LlenarDatosDeCuadricula()
    > lblMensaje.Text = lblMensaje.Text & e.Item.cells(0).Text
    > End Sub
    > ' ----------------------------------------------------------------------
    > function ExecuteStatement(strSQL)
    > Dim objCmd As New OleDbCommand(strSQL, Conn)
    >
    > try
    > objCmd.Connection.Open()
    > lblmensaje2.text=""
    > objCmd.ExecuteNonQuery()
    > catch ex As Exception
    > lblMensaje.Text = "consulta:<br>" & strSQL & "<br>Error al
    > actualizar la base de datos.<br> " & ex.tostring()
    > End try
    >
    > objCmd.Connection.Close()
    > End function
    >

    ' --------------------------------------------------------------------------
    >
    >
     
    Rick Spiewak, Apr 26, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. papaja
    Replies:
    4
    Views:
    2,015
    Hans Kesting
    Dec 5, 2005
  2. Replies:
    3
    Views:
    9,439
  3. Olivier Noblanc ATOUSOFT

    import doesn't work as i want

    Olivier Noblanc ATOUSOFT, Jan 31, 2005, in forum: Python
    Replies:
    4
    Views:
    456
    John Lenton
    Feb 1, 2005
  4. Archie
    Replies:
    6
    Views:
    480
    mingze zhang
    Jun 30, 2010
  5. Fred Zolar
    Replies:
    0
    Views:
    325
    Fred Zolar
    Apr 1, 2004
  6. P. A.
    Replies:
    0
    Views:
    234
    P. A.
    Sep 4, 2009
  7. Richard \(MrBonus\)

    onBeforeUnload doesn't work quite the way I want it too

    Richard \(MrBonus\), Sep 2, 2004, in forum: Javascript
    Replies:
    1
    Views:
    185
    Robert
    Sep 7, 2004
  8. PerlFAQ Server

    FAQ 4.6 Why doesn't & work the way I want it to?

    PerlFAQ Server, Jan 22, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    154
    PerlFAQ Server
    Jan 22, 2011
Loading...