Update unable to find...

hog

Well-known member
Joined
Mar 17, 2003
Messages
984
Location
UK
This one is driving me nuts as I have identical code in multiple forms which work fine, but for some reason this one does not!

Code:
 Try

             empty equipment dataset prior to refreshing

            Me.DataSetAssets1.Clear()

             regenerate item dataset to reflect changes

            Me.OleDbAdapterAssets.Update(Me.DataSetAssets1)

             fill the datasets with refreshed data

            Me.OleDbAdapterAssets.Fill(Me.DataSetAssets1)

 Catch objException As Exception

            ShowError("Location:   Class frmAssets" & ControlChars.CrLf & ControlChars.CrLf & _
                      "Procedure:  ResetDataset" & ControlChars.CrLf & ControlChars.CrLf & _
                      "Error Text: " & objException.Message)

 End Try

An error occurs at the .Update line which reports the following:

Update unable to find TableMapping
or DataTable Table.

If I generate and preview the data adapter in design mode it works OK?
 
re:

is the form in question identical to the others in properties? Shared member?
Try running the code without the update string and see if it executes. If it does then it is NOT a matter of the program not finding the table or table mapping. Im assuming your using the same modal dataset to access it from multiple forms?
 
Why would you call Clear then Update? I dont see how the Update would do anything since you just cleared the DataSet? Maybe you want Clear then Fill and leave out the Update line...

-ner
 
the selectcommand text is set elsewhere and this code is called to refresh the combobox thats bound to the dataset. There if a user selects they only want to see live records the clear method empties the dataset and the update reloads with just the live records. Likewise if the user want to see live and dead records the same process happens. And again if new records are appended then the reload takes place.
 
OK I have narrowed down to when the error occurs. It happens in the Windows Form Designer Generated Code when InitializeComponent() is called.

The section of code I posted above is in a RadioButton CheckedChanged event, which InitalizeComponent() is obviously calling?

This happens on all the other forms Ive coded this way but they are OK??

I have deleted all sections of related code, the dataset and the data adapter and re entered it and it is still happening.

Any ideas?
 
not sure if this is what you want?

Code:
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.OleDbAdapterAssets.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "tblAsset", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("assetid", "assetid"), New System.Data.Common.DataColumnMapping("active", "active"), New System.Data.Common.DataColumnMapping("model", "model"), New System.Data.Common.DataColumnMapping("serial", "serial"), New System.Data.Common.DataColumnMapping("supplierid", "supplierid"), New System.Data.Common.DataColumnMapping("type", "type")})})

I thought maybe the first mention of Table above was to blame, but it is not as all other forms are identical to this, apart from actaul table and field names
 
When you call the Fill(DataSet) method, the dataadapter creates a Data Table named Table and populates it with the rows returned from the data source.

When you call the Update(DataSet) method, the dataadapter updates the data source form a Data Table named Table in the specified DataSet.

When you call the Clear method of a DataSet, you empty all the tables in the DataSet.

The Table mentioned in the error message has been emptied by your clear method before you then try to use it to update your datasource in the snippet of code you have shown us.

Im not following why you implement them in the way have shown us, or how/why it would work in any Form.



Jon
 
Originally posted by hog


The section of code I posted above is in a RadioButton CheckedChanged event, which InitalizeComponent() is obviously calling?

This happens on all the other forms Ive coded this way but they are OK??

On these forms i.e. those that appear to not be generating the error, is the RadioButton CheckedChanged event firing?

Might explain why it only happens on the Form in question: it may be the only Form firing this event.

Jon
 
OK this might explain why I do it this way.

This section fires when a user clicks a radio button to say they want to see live only or live and archived items:

Code:
Private Sub Radiobutton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
         Handles radLiveOnly.CheckedChanged, radLiveAndArchived.CheckedChanged

         only do this if form is not refreshing

        If Not blnRefreshingForm Then

            Dim ctlSender As RadioButton = DirectCast(sender, RadioButton)

             ensure we are pointing at correct data

            Me.OleDbConnAssets.ConnectionString = gconnConnection

             determine who called this event and set selectcommand text accordingly

            Select Case ctlSender.Name

                Case "radLiveOnly"

                    Me.OleDbAdapterAssets.SelectCommand.CommandText = "SELECT assetid, supplierid, model, type, [ + type + ] " & _
                                                                      "+   + model +   + serial AS description FROM tblAsset WHERE (active = - 1) ORDER BY type"

                Case "radLiveAndArchived"

                    Me.OleDbAdapterAssets.SelectCommand.CommandText = "SELECT assetid, supplierid, model, type, [ + type + ] " & _
                                                                      "+   + model +   + serial AS description FROM tblAsset ORDER BY type"

            End Select

             refresh the suppliers combo box

            ResetDataset()

        End If

End Sub

Private Function ResetDataset()

        Try

             empty asset dataset prior to refreshing

            Me.DataSetAssets1.Clear()

             regenerate asset dataset to reflect changes

            Me.OleDbAdapterAssets.Update(Me.DataSetAssets1)

             fill the dataset with refreshed data

            Me.OleDbAdapterAssets.Fill(Me.DataSetAssets1)

        Catch objException As Exception

            ShowError("Location:   Class frmAssets" & ControlChars.CrLf & ControlChars.CrLf & _
                     "Procedure:  ResetDataset" & ControlChars.CrLf & ControlChars.CrLf & _
                    "Error Text: " & objException.Message)

        End Try

End Function

therefore though this code a combobox on the form will display either all live or live and archived depending on which radio button they click.

this method works perfectly fine on five other forms?
 
But you are trying to update it with an empty table since you have cleared all the tables in the dataset.

Try commenting out the update line.*nudge*
 
I dont think you follow what Im doing?

this code works as is in five other forms, so I cannot see why it wont work here. If I comment out the update line I get an error on the Fill line saying the select statement is not set. Yet it is set!
 
Further explained. Lets say the original sql returned 2 records, if I dont use .clear first as shown then each time the .fll is called the record count is doubled.
 
I think no one is disputing the Clear() method call. Its the call to Update immediately afterwards that seems pointless because you just cleared all the data that you are requesting the update for. If you feel you need this line because it has some strange side effect on your select command, Id still suggest you comment it out and dig deeper to find the root of the problem.

As for the "code works as is on five other forms"... I cant count the number of times Ive said "... but its the exact same code" only to remember that little difference hours of debugging later. If its truly the same code perhaps you should consider inheriting from a base form that can do this work for you?
 
OK perhaps I should explain further as reading my past posts this bit is not mentioned...oops!

There is a combobox on the form that lists all items live and archived.

The user can choose to see live only or live and archived by using the radio buttons.

There is also the need to refresh the data in the combobox to read from the database again as there is all probability that another user may have archived or appended new items to the list.

Therefore....the update method reads the database again to ensure it has an up to date listing of items in the database.

So from this perspective surely the update method is record?
 
More food for thought....

OK so I get this error when the form opens. When I click OK to acknowledge the error and allow the app to continue the form acts exactly as the others.

I can use the radio buttons to filter the combobox and the call to ResetDataset works. If I add additional records to the database then the call to ResetDataset works perfect (just as in all the other forms).

Therefore there is something going on in the Windows Designer code that is causing the grief!
 
Back
Top