Private Sub DataGridView1_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles DataGridView1.UserDeletingRow
If (Not e.Row.IsNewRow) Then
Dim response As DialogResult = MessageBox.Show("Are you sure you want to delete this row?", "Delete row?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If (response = DialogResult.No) Then
e.Cancel = True
End If
_Conn = New SqlConnection(_ConnString)
Try
Dim theRow As Integer = DataGridView1.CurrentRow.Index
Dim gridRow As DataGridViewRow = DataGridView1.Rows(theRow)
Dim depositID As Integer = 0
If gridRow.Cells(0).EditedFormattedValue.ToString().Length() > 0 Then
depositID = Int32.Parse(gridRow.Cells(0).EditedFormattedValue.ToString())
End If
Dim DelCommandString As String = "usp_Deposit_Delete"
Dim cmdDEL As New SqlCommand(DelCommandString, _Conn)
cmdDEL.CommandType = CommandType.StoredProcedure
Dim myUtil As New Utils
With myUtil
.AddParamToSQLCmd(cmdDEL, "@DepositID", SqlDbType.Int, 4, ParameterDirection.Input, depositID)
End With
_da.DeleteCommand = cmdDEL
_Conn.Open()
cmdDEL.ExecuteNonQuery()
'_da.Update(_dsGrid.Tables("OneDay"))
'_dsGrid.AcceptChanges()
_Conn.Close()
Catch ex As Exception
MessageBox.Show("Error in Deleting Data: " & ex.Message & vbCrLf & vbCrLf & ex.StackTrace)
Finally
_Conn.Dispose()
End Try
updateBindingSource()
If BindingNavigator1.BindingSource.Count < 0 Then
'getDepositsForSelectedDate()
DataGridView1.DataSource = _dsGrid.Tables("OneDay")
DataGridView1.Refresh()
End If
End If
End Sub