Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to delete multiple records 4m DB using checkboxes in datagridview?

$
0
0
i hav a table created in oracle supplier(Name, Contact1,Contact2).
i hav used a datagridview for retriveing the supplier table values on form load. what i want is when the user selects multiple checkboxes, then onclick of delete button the records should be deleted from the database & the datagridview should be refreshed with the edited data. also please tell how to write the delete query for the same in the db code.
my code is as follows:

Private CheckboxColumn As New DataGridViewCheckBoxColumn()

Private Sub SupplierContact_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.CheckboxColumn.HeaderText = "Tick to Delete"
Me.DataGridView1.Columns.Insert(0, CheckboxColumn)
AddHandler DataGridView1.CurrentCellDirtyStateChang… AddressOf dataGridView1_CurrentCellDirtyStateChang…
AddHandler DataGridView1.CellValueChanged, AddressOf dataGridView1_CellValueChanged

End Sub

Private Sub dataGridView1_CurrentCellDirtyStateChang… sender As Object, ByVal e As EventArgs)
If DataGridView1.IsCurrentCellDirty Then
DataGridView1.CommitEdit(DataGridViewDat…
End If
End Sub

Private Sub dataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
If DataGridView1.Columns(e.ColumnIndex).Nam… = "CheckboxColumn" And e.RowIndex = 0 Then
Dim i As Int32
For i = 1 To DataGridView1.Rows.Count
DataGridView1.Rows(i).Cells("CheckboxCol… = DataGridView1.CurrentCell.Value
Next

End If
End Sub

Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click
Dim RowsToDelete As New List(Of DataGridViewRow)
Try
Dim myOracleConnection As New OracleConnection("User Id=shweja;Password=shweja")
myOracleConnection.Open()
Dim myOracleTransaction As OracleTransaction = myOracleConnection.BeginTransaction()
Dim myOracleCommand As OracleCommand = myOracleConnection.CreateCommand()
myOracleCommand.CommandText = "delete from supplier where Name = ' " & scn.Text & "'"
Dim Delete = MessageBox.Show("Are You Sure to Delete", "Query", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If (Delete = vbYes) Then
myOracleCommand.ExecuteNonQuery()
MessageBox.Show("Record Deleted successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
myOracleTransaction.Commit()
myOracleConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub



also it gives an error that execute requires an obj for transaction.
please help...

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>