Poops
2013-03-02 07:33:44 UTC
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...