简体   繁体   中英

how to delete selected row from database in GridControl

I am new on DevExpress. I retrieve data from database to gridview and can display them so far. However, I have a button which makes several modifications when user clicks on it.

I can remove the selected row from gridview. So my obvious question is how can I delete selected rows from database in gridview.

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


    Dim cevap As DialogResult = DevExpress.XtraEditors.XtraMessageBox.Show("Are you sure?", "Dikkat!", MessageBoxButtons.YesNo)
    If cevap = Windows.Forms.DialogResult.No Then Exit Sub

    Dim command As New SqlCommand()
    command.Connection = spcc.SqlCon

    'command.CommandText = "DELETE FROM EBARPARAMETER WHERE ID = '" & GridView1.what? & "' "



    Dim read As SqlDataReader
    read = command.ExecuteReader()
    GridView1.DeleteRow(GridView1.FocusedRowHandle)

Take a look at the Posting Data to a Connected Database help-article: The GridView.DeleteRow method removes a row from a grid's View and also deletes the object which represents this row in the GridControl's data source, but not from a database. To accomplish your task, you need to post changes to the database manually , for example using corresponding the methods of a Data Adapter object or EF-context.

GridView1.what?

To get row objects that correspond to specific row handles, use the ColumnView.GetRow or ColumnView.GetDataRow method. In specific cases, you may need to obtain indexes of rows in the bound data source that correspond to specific row handles in Views. To do this, use the ColumnView.GetDataSourceRowIndex method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM