Home All Groups Group Topic Archive Search About

Update unable to find TableMapping

Author
24 Oct 2006 2:22 PM
sxsrira
Dear friends,

       I ran into this exception while trying to update excel through
Ado.Net. When i searched google found there are similar queries left
unresolved. I identified the mistake i have done. Hence i thought to
post it on the net and make it available, just in case if anyone
requires.

       Solution given as a reply to a query posted (given below) to
this group some time back.

       Solution:
              mdaGridData.Update(dsChanges)   'Error occurred here

              Should have to be rewritten as
              mdaGridData.Update(dsChanges,"Test")

Thanks,
Saran.

Original Post:
I am relatively new to ADO.Net and I'm sure this is where my trouble
lies,
but I am having trouble understanding the relationship between the data

adapter and the dataset, and using the data adapter to update the data
set.

I am using the OleDbDataAdapter, and I create it like:
        'create the data adapter


        'mdaGridData is a private form variable of type
OleDbDataAdapter


        mdaGridData= New OleDbDataAdapter("Select * From TestTable",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Exec5.mdb;User
Id=;Password=;")


Next, I create my dataset:


        Dim ldsDAClass As DataSet


        ldsDAClass = New DataSet


        'fill the dataset


        mdaGridData.Fill(ldsDAClass, "Test")


And then bind it to a grid:


    dGrid.DataSource = ldsDAClass


My grid pops up with the data showing. When I make changes to the grid
and
then select the Update button on my form, I have to code:


        Dim dsChanges As DataSet = New DataSet


        dsChanges = mdsGridData.GetChanges


        mdaGridData.Update(dsChanges)


When my code gets to the Update statement, I get the error:


Update unable to find TableMapping['Table'] or DataTable 'Table'.


So, after doing some reading, I read that it may be the data adapters
need
to have a table mapping, so I added the following code under the line
mdaGridData= New OleDbDataAdapter("Select * From TestTable",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Exec5.mdb;User
Id=;Password=;"):


    mdaGridData.TableMappings.Add("ID", "ID")


    mdaGridData.TableMappings.Add("Description", "Description")


    mdaGridData.TableMappings.Add("Price", "Price")


Apparently, this was not the problem since this still resulted in the
same
error.


Can someone tell me what I am doing wrong? Why do you have to do
TableMappings? Must they include each column in the table or just the
columns in the result set?

AddThis Social Bookmark Button