retrieve table names

  • Thread starter Thread starter tin
  • Start date Start date
T

tin

I'm writing a CommandBuilder.

Is it possible to retrieve from schema data the original names of the tables
involved
in a select clause?

I noticed that a dataSet schema reports a generic "table"
on the property "TableName" and it does not report the name of the table
that fills the dataset.

TableMappings is not a solution for me because the query is my only input.

There is a way, by the methods of a dataAdapter o releated objects, to
retrive
that information ? I don't like to parse the query to get the table name. It
could be an
unsafe workoround.
 
I would use SQL DMO, which is a COM library (interop required). I do not
know of a "new" .NET only way to accomplish iterating through a
collection/enumeration of SQL objects.

You could also query the master database, but could open a security hole.
DMO is safer.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

****************************************************************************
****
Think Outside the Box!
****************************************************************************
****
 
I've written similar code in the past for a tool to build
code for DataAdapter updating logic. Try calling
DataAdapter.SelectCommand.ExecuteReader and then calling
GetSchemaTable on the resulting DataReader. On the call to
ExecuteReader, specify a CommandBehavior combining KeyInfo and
SchemaOnly to include key information (base table and column
names, key column(s)) and omit the query results.

DataReader.GetSchemaTable returns a DataTable of schema
information about the original query. Each row in this DataTable
corresponds to a column in the resultset for the original query.
The simplest way to digest this information is to bind it to a
DataTable and show it on a form.

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.
 
tin and gomezdegomera are the same person.
I assigned tin as my nickname for an error.

I retrived the schema infos by the KeyInfo Command Behavior of a IDataReader
as you told me.
basetablename element contains the info I neeeded.

I'd like to retrieve the other column infos from that schema to create the
statament of the commandbuilder but I have a incompatibility doubt.

I want to use that infos (ColumnSize, ColumnName, DataType) for a generic
IDbDataAdapter supporting SQL.
So, is there a common schema of the table returned by GetSchemaTable method
the the different providers must follow? Where can I download that schema?

I fear that for example ColumnSize that is valid for a OdbcConnection does
not exist with the same name in another IDbConnection.
The same doubt about basetablename (and this would be worse).

Otherwise I have to retrieve the other schema info throw the FillSchema
method of the DataSet.
 
Back
Top