Hello,
I recently have decided that it may be useful to learn how to make a small application using VB. This being my fist App that does more than 1+1=2 I need some help. I have created a small app that is a memo pad that uses a database to store data. Or at least it is supposed to... Keep in mind that I was using Bits and pieces of other code...
Ok so here is the error I get when I am debugging it.
¡°A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll
DefaultSource Error: 2 : Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.¡±
And sometimes
"A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll
DefaultSource Error: 2 : Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
I get this after i Hit the deleat button and then try and do something like hit the add button or when i change data and click on another entry....
This is the code for the control form
Public Class Control
Dim WithEvents XTable As MySpace.DatabaseDataSet.InfoTableDataTable
Dim IsUpdating As Boolean = False
Private Sub Control_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.XTable = Me.DatabaseDataSet.InfoTable
If Me.LoadData() = 0 Then
Me.InfoTableBindingSource.AddNew()
End If
End Sub
Private Sub dt_rowChanged(ByVal sender As Object, ByVal e As Data.DataRowChangeEventArgs) Handles XTable.RowChanged
If Me.IsUpdating Then
Return
End If
Dim DataRow As DatabaseDataSet.InfoTableRow = CType(e.Row, DatabaseDataSet.InfoTableRow)
If DataRow IsNot Nothing Then
Me.SaveData()
End If
End Sub
Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
Me.InfoTableBindingSource.AddNew()
End Sub
Private Sub RemoveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveButton.Click
Me.DeleteCurrent()
End Sub
Friend Function LoadData() As Integer
Dim rowsLoaded As Integer = 0
Try
Me.IsUpdating = True
rowsLoaded = Me.InfoTableTableAdapter.Fill(Me.DatabaseDataSet.InfoTable)
Catch ex As Exception
MsgBox(String.Format("There was a problem loading data: {0}", ex.Message))
My.Application.Log.WriteException(ex)
Finally
Me.IsUpdating = False
End Try
Return rowsLoaded
End Function
Friend Function SaveData() As Integer
If Me.IsUpdating Then
Return 0
End If
Dim rowsSaved As Integer = 0
Try
If Me.DatabaseDataSet.HasChanges Then
IsUpdating = True
rowsSaved = Me.InfoTableTableAdapter.Update(Me.DatabaseDataSet.InfoTable)
End If
Catch ex As Exception
MsgBox(String.Format("There was a problem saving data: {0}", ex.Message))
My.Application.Log.WriteException(ex)
Finally
IsUpdating = False
End Try
Return rowsSaved
End Function
Friend Sub DeleteCurrent()
If (Me.InfoTableBindingSource.Count > 0) AndAlso (Me.InfoTableBindingSource.Current IsNot Nothing) Then
Dim msgText As String = String.Format("Are you sure you want to permanently delete this")
Dim result As MsgBoxResult = MsgBox(msgText, MsgBoxStyle.YesNo, "OK to delete ")
If result = MsgBoxResult.Yes Then
Me.InfoTableBindingSource.RemoveCurrent()
End If
If InfoTableBindingSource.Count = 0 Then
Me.InfoTableBindingSource.AddNew()
End If
End If
End Sub
End Sub
End Class
Thank you so much for Your help!