G
Gregory A Greenman
I am using VB.Net 2003 with an MS Access database. This program is
one I wrote myself for my own use. It has been in use for a couple
of years. I am using a strongly typed dataset with several tables.
The first field in every table is named "ID" and is the table's
Primary Key.
Recently, I added a couple of new tables. When I ran my save
routine, their data was saved properly, until a couple of days ago.
Now, when my program tries to save their data, I get an error
message that says "There is no Original data to access".
Here's some of my code:
------------ begin code ------------
Public Class frmMain
...
Dim cmdRefresh As OleDbCommand
...
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
...
cmdRefresh = New OleDbCommand("SELECT @@IDENTITY", cn)
...
AddHandler adpInventory.RowUpdated, AddressOf
HandleInventoryRowUpdated
AddHandler adpSalesHeader.RowUpdated, AddressOf
HandleSalesHeaderRowUpdated
...
End Sub
Private Sub HandleInventoryRowUpdated(ByVal sender As Object, ByVal
e As OleDbRowUpdatedEventArgs)
If e.Status = UpdateStatus.Continue AndAlso (e.StatementType =
StatementType.Insert) Then
e.Row("ID") = CInt(cmdRefresh.ExecuteScalar)
e.Row.AcceptChanges()
End If
End Sub
Private Sub HandleSalesHeaderRowUpdated(ByVal sender As Object,
ByVal e As OleDbRowUpdatedEventArgs)
Dim x As Integer
If e.Status = UpdateStatus.Continue AndAlso (e.StatementType =
StatementType.Insert) Then
x = CInt(cmdRefresh.ExecuteScalar)
Console.WriteLine("RowState = " & e.Row.RowState.ToString)
Console.WriteLine("Current ID = " & e.Row("ID").ToString)
Console.WriteLine("Original ID = " & e.Row("ID",
DataRowVersion.Original).ToString)
'Next line generates: There is no Original data to access
e.Row("ID") = x
e.Row.AcceptChanges()
End If
End Sub
------------ end code ------------
When my program is saving new Inventory rows, it works fine. When
it saves new SalesHeader rows it gives me the error message at the
line indicated above. The console.writelines generate:
RowState = Unchanged
Current ID = -1
Original ID = -1
The only differences in the Handle...RowUpdated procedures are ones
I put in to try to debug this error.
A few days ago, I added some calculated fields to the strongly
typed dataset. I'm not sure if this is was when the problem began.
Removing those fields did not make the problem go away.
Can anyone suggest anything, short of upgrading to a newer version
of Visual Studio (which I plan to do soon anyway), that might solve
this problem?
Thanks for any help.
one I wrote myself for my own use. It has been in use for a couple
of years. I am using a strongly typed dataset with several tables.
The first field in every table is named "ID" and is the table's
Primary Key.
Recently, I added a couple of new tables. When I ran my save
routine, their data was saved properly, until a couple of days ago.
Now, when my program tries to save their data, I get an error
message that says "There is no Original data to access".
Here's some of my code:
------------ begin code ------------
Public Class frmMain
...
Dim cmdRefresh As OleDbCommand
...
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
...
cmdRefresh = New OleDbCommand("SELECT @@IDENTITY", cn)
...
AddHandler adpInventory.RowUpdated, AddressOf
HandleInventoryRowUpdated
AddHandler adpSalesHeader.RowUpdated, AddressOf
HandleSalesHeaderRowUpdated
...
End Sub
Private Sub HandleInventoryRowUpdated(ByVal sender As Object, ByVal
e As OleDbRowUpdatedEventArgs)
If e.Status = UpdateStatus.Continue AndAlso (e.StatementType =
StatementType.Insert) Then
e.Row("ID") = CInt(cmdRefresh.ExecuteScalar)
e.Row.AcceptChanges()
End If
End Sub
Private Sub HandleSalesHeaderRowUpdated(ByVal sender As Object,
ByVal e As OleDbRowUpdatedEventArgs)
Dim x As Integer
If e.Status = UpdateStatus.Continue AndAlso (e.StatementType =
StatementType.Insert) Then
x = CInt(cmdRefresh.ExecuteScalar)
Console.WriteLine("RowState = " & e.Row.RowState.ToString)
Console.WriteLine("Current ID = " & e.Row("ID").ToString)
Console.WriteLine("Original ID = " & e.Row("ID",
DataRowVersion.Original).ToString)
'Next line generates: There is no Original data to access
e.Row("ID") = x
e.Row.AcceptChanges()
End If
End Sub
------------ end code ------------
When my program is saving new Inventory rows, it works fine. When
it saves new SalesHeader rows it gives me the error message at the
line indicated above. The console.writelines generate:
RowState = Unchanged
Current ID = -1
Original ID = -1
The only differences in the Handle...RowUpdated procedures are ones
I put in to try to debug this error.
A few days ago, I added some calculated fields to the strongly
typed dataset. I'm not sure if this is was when the problem began.
Removing those fields did not make the problem go away.
Can anyone suggest anything, short of upgrading to a newer version
of Visual Studio (which I plan to do soon anyway), that might solve
this problem?
Thanks for any help.