TableName of a DataTable wrong!

  • Thread starter Thread starter David Sceppa
  • Start date Start date
D

David Sceppa

Mike,

When you issue a query like "SELECT CustomerID, CompanyName
FROM Customers", the name or the table/view/resultset is not
included with the results. By default, the DataAdapter will
assume a name of "Table". You can control this behavior by
setting the DataAdapter's TableMappings collection.

Adding the following line of code:

da.TableMappings.Add("Table", "Customers");

would have the desired effect. For more information, see the
documentation on TableMappings.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
When you create a new dataset and fill it from a dataadapter, the tableName
property of the individual datatable is not the name of the table. Why is
this?

DataSet ds=new DataSet("Northwind");
DbContext myContext = new DbContext("SQL");
myContext.ConnectionString =
"server=DEVSTL\FacilityData;database=Northwind;";
myContext.Connection.Open();
try
{
IDbCommand cmd = myContext.DbTemplate.Command(
"SELECT * FROM Customers",
myContext.Connection);
IDbDataAdapter da = myContext.DbTemplate.DataAdapter(cmd);
da.Fill(ds);
}
finally{myContext.Connection.Close();}

ds.Tables[0].TableName is "Table", but should be "Customers"!

Mike
 
I had that wrong. It does work.

DataSet ds=new DataSet("Northwind");
....
IDbDataAdapter da = myContext.DbTemplate.DataAdapter(cmd);
da.TableMappings.Add("Table", "Customers")
da.Fill(ds);

I have not yet tested it with my ExportXML function, but I don't see any
problems yet.

Thanks,
Mike
 
Back
Top