TableName of a DataTable wrong!

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.
 
M

Michael Lang

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
 
M

Michael Lang

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top