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. Advertising

  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. Advertising

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:
    1,819
    Hans Kesting
    Dec 5, 2005
  2. Replies:
    3
    Views:
    8,421
  3. Olivier Noblanc ATOUSOFT

    import doesn't work as i want

    Olivier Noblanc ATOUSOFT, Jan 31, 2005, in forum: Python
    Replies:
    4
    Views:
    362
    John Lenton
    Feb 1, 2005
  4. Fred Zolar
    Replies:
    0
    Views:
    223
    Fred Zolar
    Apr 1, 2004
  5. P. A.
    Replies:
    0
    Views:
    148
    P. A.
    Sep 4, 2009
Loading...

Share This Page