Convince me this is a table name or "TableMapping" error?

  • Thread starter Thread starter Earl
  • Start date Start date
E

Earl

Head-scratcher here .... I have a routine that updates manufacturer data
using the dataAdapter and dataSet. My code correctly opens the connection,
loads up the existing table, and adds a row to the DataTable. But when it
gets to updating the adapter, gives an exception with the error message:

"Update unable to find TableMapping['dtManufacturer'] or Data Table
'dtManufacturer'."

Yet the data table name is correct, and the column names perfectly match the
database names. I've checked syntax, variable names, etc. I am quite stumped
on this, and having read quite a bit about TableMapping -- I am not
convinced that is the problem. Is there any other screwball reason I could
be getting this error?

Here is the snippet that is failing (on the Update command):

Dim dsChanges As DataSet
dsChanges = dsManufacturers.GetChanges
dsManufacturers.AcceptChanges()
daManufacturers.Update(dsChanges, "dtManufacturer")
 
Earl:

I don't think you'll have a table named dtManufacturer in the dataset
created from GetChanges. You should just be able to call update on the
dataset daManufacturers.Update(dsChanges) or reference it by table index
after verifying that it's the table you want
daManufacturer.Update(dsChanges.Tables[0]);

Just for giggles, try this line of code

Dim i as INteger = dsChanges.Tables.Count
For x as INteger = 0 to i-1

Debug.WriteLine(dsChanges.Tables(x).TableName())

Next

The see the output --- check if there is a table named dtManufacturer. There
should only be one table anyway, but just to make sure in case there are
multiple tables we'll grab all of their names. My guess is that table 0
isn't name dtManufacturers..
 
Good ideas, but no joy yet. The command:

Dim dsChanges As DataSet
Dim i As Integer = dsChanges.Tables.Count

Gives me an error "Object reference not set to an instance of an object".
Apparently I cannot assign a variable to dataset count, so I changed it to:

Dim i As Integer = dsChanges.Tables.Count.MaxValue and this does return a
value of 2147483647, which I am interpreting to mean no count at all.

One other issue I considered was not having IIS on the computer with
SQLServer (which is not the development pc). But adding IIS and opening up
the permissions did not resolve this problem either.


William Ryan eMVP said:
Earl:

I don't think you'll have a table named dtManufacturer in the dataset
created from GetChanges. You should just be able to call update on the
dataset daManufacturers.Update(dsChanges) or reference it by table index
after verifying that it's the table you want
daManufacturer.Update(dsChanges.Tables[0]);

Just for giggles, try this line of code

Dim i as INteger = dsChanges.Tables.Count
For x as INteger = 0 to i-1

Debug.WriteLine(dsChanges.Tables(x).TableName())

Next

The see the output --- check if there is a table named dtManufacturer. There
should only be one table anyway, but just to make sure in case there are
multiple tables we'll grab all of their names. My guess is that table 0
isn't name dtManufacturers..

Earl comcast net> said:
Head-scratcher here .... I have a routine that updates manufacturer data
using the dataAdapter and dataSet. My code correctly opens the connection,
loads up the existing table, and adds a row to the DataTable. But when it
gets to updating the adapter, gives an exception with the error message:

"Update unable to find TableMapping['dtManufacturer'] or Data Table
'dtManufacturer'."

Yet the data table name is correct, and the column names perfectly match the
database names. I've checked syntax, variable names, etc. I am quite stumped
on this, and having read quite a bit about TableMapping -- I am not
convinced that is the problem. Is there any other screwball reason I could
be getting this error?

Here is the snippet that is failing (on the Update command):

Dim dsChanges As DataSet
dsChanges = dsManufacturers.GetChanges
dsManufacturers.AcceptChanges()
daManufacturers.Update(dsChanges, "dtManufacturer")
 
More on this:

Set up a richtextbox and passed it the results of the dsChanges.GetChanges
by using dsChanges.GetXML. The textbox showed that the name of the table
was "dtManufacturerTable".

So I changed the update method to call this table instead. Now I get the
error: "Update requires a valid Insert Command when passed DataRow
collection with new rows."


Earl comcast net> said:
Good ideas, but no joy yet. The command:

Dim dsChanges As DataSet
Dim i As Integer = dsChanges.Tables.Count

Gives me an error "Object reference not set to an instance of an object".
Apparently I cannot assign a variable to dataset count, so I changed it to:

Dim i As Integer = dsChanges.Tables.Count.MaxValue and this does return a
value of 2147483647, which I am interpreting to mean no count at all.

One other issue I considered was not having IIS on the computer with
SQLServer (which is not the development pc). But adding IIS and opening up
the permissions did not resolve this problem either.


William Ryan eMVP said:
Earl:

I don't think you'll have a table named dtManufacturer in the dataset
created from GetChanges. You should just be able to call update on the
dataset daManufacturers.Update(dsChanges) or reference it by table index
after verifying that it's the table you want
daManufacturer.Update(dsChanges.Tables[0]);

Just for giggles, try this line of code

Dim i as INteger = dsChanges.Tables.Count
For x as INteger = 0 to i-1

Debug.WriteLine(dsChanges.Tables(x).TableName())

Next

The see the output --- check if there is a table named dtManufacturer. There
should only be one table anyway, but just to make sure in case there are
multiple tables we'll grab all of their names. My guess is that table 0
isn't name dtManufacturers..

Earl comcast net> said:
Head-scratcher here .... I have a routine that updates manufacturer data
using the dataAdapter and dataSet. My code correctly opens the connection,
loads up the existing table, and adds a row to the DataTable. But when it
gets to updating the adapter, gives an exception with the error message:

"Update unable to find TableMapping['dtManufacturer'] or Data Table
'dtManufacturer'."

Yet the data table name is correct, and the column names perfectly
match
the
database names. I've checked syntax, variable names, etc. I am quite stumped
on this, and having read quite a bit about TableMapping -- I am not
convinced that is the problem. Is there any other screwball reason I could
be getting this error?

Here is the snippet that is failing (on the Update command):

Dim dsChanges As DataSet
dsChanges = dsManufacturers.GetChanges
dsManufacturers.AcceptChanges()
daManufacturers.Update(dsChanges, "dtManufacturer")
 
I went over and read William Vaughn's article on the command builder ...
that was the secondary problem. Nice to know something creates commands in
the background, but I am feeling somewhat sentimental for good ole' ADO ...
William Ryan eMVP said:
Earl:

I don't think you'll have a table named dtManufacturer in the dataset
created from GetChanges. You should just be able to call update on the
dataset daManufacturers.Update(dsChanges) or reference it by table index
after verifying that it's the table you want
daManufacturer.Update(dsChanges.Tables[0]);

Just for giggles, try this line of code

Dim i as INteger = dsChanges.Tables.Count
For x as INteger = 0 to i-1

Debug.WriteLine(dsChanges.Tables(x).TableName())

Next

The see the output --- check if there is a table named dtManufacturer. There
should only be one table anyway, but just to make sure in case there are
multiple tables we'll grab all of their names. My guess is that table 0
isn't name dtManufacturers..

"Earl comcast net>" <brikshoe<at.> wrote in message
Head-scratcher here .... I have a routine that updates manufacturer data
using the dataAdapter and dataSet. My code correctly opens the connection,
loads up the existing table, and adds a row to the DataTable. But
when
it
gets to updating the adapter, gives an exception with the error message:

"Update unable to find TableMapping['dtManufacturer'] or Data Table
'dtManufacturer'."

Yet the data table name is correct, and the column names perfectly match
the
database names. I've checked syntax, variable names, etc. I am quite
stumped
on this, and having read quite a bit about TableMapping -- I am not
convinced that is the problem. Is there any other screwball reason I could
be getting this error?

Here is the snippet that is failing (on the Update command):

Dim dsChanges As DataSet
dsChanges = dsManufacturers.GetChanges
dsManufacturers.AcceptChanges()
daManufacturers.Update(dsChanges, "dtManufacturer")
 
Earl:

Is that your exact code? If that's the case then it will throw a null
reference b/c it's not been instantiated. If this is after you called
getchanges, it would appear that there are no changes (which is the most
likely guess).

The TableMapping issue isn't likely to be related to a permissions issue.
What happened when you looped through the datatables and looked up the
tablename? I think it's probably the fact that the variable name is
dtManufacturer but 1) the table name isn't dtManufacturer and 2) The
GetChanges Datatable doesn't have a table named dtManufacturer..

You've got to look to the dsChanges and find out the table names. Just for
giggles, use an index of 0 instead of the tablename literal, that should
work b/c I'm guessing you'll only have one table in the dataset
Earl comcast net> said:
Good ideas, but no joy yet. The command:

Dim dsChanges As DataSet
Dim i As Integer = dsChanges.Tables.Count

Gives me an error "Object reference not set to an instance of an object".
Apparently I cannot assign a variable to dataset count, so I changed it to:

Dim i As Integer = dsChanges.Tables.Count.MaxValue and this does return a
value of 2147483647, which I am interpreting to mean no count at all.

One other issue I considered was not having IIS on the computer with
SQLServer (which is not the development pc). But adding IIS and opening up
the permissions did not resolve this problem either.


William Ryan eMVP said:
Earl:

I don't think you'll have a table named dtManufacturer in the dataset
created from GetChanges. You should just be able to call update on the
dataset daManufacturers.Update(dsChanges) or reference it by table index
after verifying that it's the table you want
daManufacturer.Update(dsChanges.Tables[0]);

Just for giggles, try this line of code

Dim i as INteger = dsChanges.Tables.Count
For x as INteger = 0 to i-1

Debug.WriteLine(dsChanges.Tables(x).TableName())

Next

The see the output --- check if there is a table named dtManufacturer. There
should only be one table anyway, but just to make sure in case there are
multiple tables we'll grab all of their names. My guess is that table 0
isn't name dtManufacturers..

Earl comcast net> said:
Head-scratcher here .... I have a routine that updates manufacturer data
using the dataAdapter and dataSet. My code correctly opens the connection,
loads up the existing table, and adds a row to the DataTable. But when it
gets to updating the adapter, gives an exception with the error message:

"Update unable to find TableMapping['dtManufacturer'] or Data Table
'dtManufacturer'."

Yet the data table name is correct, and the column names perfectly
match
the
database names. I've checked syntax, variable names, etc. I am quite stumped
on this, and having read quite a bit about TableMapping -- I am not
convinced that is the problem. Is there any other screwball reason I could
be getting this error?

Here is the snippet that is failing (on the Update command):

Dim dsChanges As DataSet
dsChanges = dsManufacturers.GetChanges
dsManufacturers.AcceptChanges()
daManufacturers.Update(dsChanges, "dtManufacturer")
 
That should solve the tablename exception. However, if you are getting the
other exception, it can't generate update logic for you.. And if that's the
case, it's probably b/c the table doesn't have a key. If it does, then set
make the column in dsGetChanges.Tables[0] a PrimaryKey. With that set, you
either the commandbuilder (yuck) or the DA Config Wizard should be able to
generate update logic for you. And if neither of those work, you can always
opt to roll your own logic (which is probalby the better way to go).

HTH,

Bill
Earl comcast net> said:
I went over and read William Vaughn's article on the command builder ...
that was the secondary problem. Nice to know something creates commands in
the background, but I am feeling somewhat sentimental for good ole' ADO ....
Earl:

I don't think you'll have a table named dtManufacturer in the dataset
created from GetChanges. You should just be able to call update on the
dataset daManufacturers.Update(dsChanges) or reference it by table index
after verifying that it's the table you want
daManufacturer.Update(dsChanges.Tables[0]);

Just for giggles, try this line of code

Dim i as INteger = dsChanges.Tables.Count
For x as INteger = 0 to i-1

Debug.WriteLine(dsChanges.Tables(x).TableName())

Next

The see the output --- check if there is a table named dtManufacturer.
There
should only be one table anyway, but just to make sure in case there are
multiple tables we'll grab all of their names. My guess is that
table
0
isn't name dtManufacturers..

"Earl comcast net>" <brikshoe<at.> wrote in message
Head-scratcher here .... I have a routine that updates
manufacturer
data
using the dataAdapter and dataSet. My code correctly opens the
connection,
loads up the existing table, and adds a row to the DataTable. But when
it
gets to updating the adapter, gives an exception with the error message:

"Update unable to find TableMapping['dtManufacturer'] or Data Table
'dtManufacturer'."

Yet the data table name is correct, and the column names perfectly match
the
database names. I've checked syntax, variable names, etc. I am quite
stumped
on this, and having read quite a bit about TableMapping -- I am not
convinced that is the problem. Is there any other screwball reason I
could
be getting this error?

Here is the snippet that is failing (on the Update command):

Dim dsChanges As DataSet
dsChanges = dsManufacturers.GetChanges
dsManufacturers.AcceptChanges()
daManufacturers.Update(dsChanges, "dtManufacturer")
 
Thanks for taking the journey with me William. The problem was indeed the
missing command builder declaration. The table name was
"dtManufacturerTable'. Here are the missing relevant pieces. The update is
working perfect now.

Dim daManufacturers As New SqlDataAdapter(strSQLManufacturers,
strSQLServer)
Dim cb As SqlCommandBuilder
cb = New SqlCommandBuilder(daManufacturers)
Dim dsManufacturers As New DataSet
Dim dtManufacturer As DataTable
Dim drNewManufacturer As DataRow

strSQLServer.Open()

daManufacturers.Fill(dsManufacturers, "dtManufacturerTable")
dtManufacturer = dsManufacturers.Tables("dtManufacturerTable")



William Ryan eMVP said:
That should solve the tablename exception. However, if you are getting the
other exception, it can't generate update logic for you.. And if that's the
case, it's probably b/c the table doesn't have a key. If it does, then set
make the column in dsGetChanges.Tables[0] a PrimaryKey. With that set, you
either the commandbuilder (yuck) or the DA Config Wizard should be able to
generate update logic for you. And if neither of those work, you can always
opt to roll your own logic (which is probalby the better way to go).

HTH,

Bill
Earl comcast net> said:
I went over and read William Vaughn's article on the command builder ...
that was the secondary problem. Nice to know something creates commands in
the background, but I am feeling somewhat sentimental for good ole' ADO ...
Earl:

I don't think you'll have a table named dtManufacturer in the dataset
created from GetChanges. You should just be able to call update
on
the
dataset daManufacturers.Update(dsChanges) or reference it by table index
after verifying that it's the table you want
daManufacturer.Update(dsChanges.Tables[0]);

Just for giggles, try this line of code

Dim i as INteger = dsChanges.Tables.Count
For x as INteger = 0 to i-1

Debug.WriteLine(dsChanges.Tables(x).TableName())

Next

The see the output --- check if there is a table named dtManufacturer.
There
should only be one table anyway, but just to make sure in case
there
are
multiple tables we'll grab all of their names. My guess is that
table
0
isn't name dtManufacturers..

"Earl comcast net>" <brikshoe<at.> wrote in message
Head-scratcher here .... I have a routine that updates manufacturer
data
using the dataAdapter and dataSet. My code correctly opens the
connection,
loads up the existing table, and adds a row to the DataTable.
But
when
it
gets to updating the adapter, gives an exception with the error
message:

"Update unable to find TableMapping['dtManufacturer'] or Data Table
'dtManufacturer'."

Yet the data table name is correct, and the column names perfectly
match
the
database names. I've checked syntax, variable names, etc. I am quite
stumped
on this, and having read quite a bit about TableMapping -- I am not
convinced that is the problem. Is there any other screwball
reason
 
Back
Top