Question:
how to delete multiple records from database using checkboxes in datagridview in vb.net?
Poops
2013-03-02 07:33:44 UTC
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 plz 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.CurrentCellDirtyStateChanged, AddressOf dataGridView1_CurrentCellDirtyStateChanged
AddHandler DataGridView1.CellValueChanged, AddressOf dataGridView1_CellValueChanged

End Sub

Private Sub dataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As EventArgs)
If DataGridView1.IsCurrentCellDirty Then
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub

Private Sub dataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
If DataGridView1.Columns(e.ColumnIndex).Name = "CheckboxColumn" And e.RowIndex = 0 Then
Dim i As Int32
For i = 1 To DataGridView1.Rows.Count
DataGridView1.Rows(i).Cells("CheckboxColumn").Value = 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.
plz help...
Three answers:
Siju
2013-03-03 23:33:36 UTC
Refer the below link



http://stackoverflow.com/questions/5967674/deleting-a-record-multiple-records-with-a-checkboxphp-mysql



http://stackoverflow.com/questions/6388613/delete-multiple-rows-with-checkbox-form-db-table
?
2016-10-28 14:25:25 UTC
A table of contacts (call, handle, etc., and a contactID). A table of telephone numbers conserving the quantity and the contactID. For any given touch, go with all numbers having that touch's contactID.
anonymous
2013-03-02 07:40:06 UTC
Too kuch


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...