SchemaTable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using the following code to obtain information about any table in a
database. Now _schemaTable contains the info about the table and one of its
fields is "IsKey" which as far as I know should identify the columns that are
the primary keys in the table. Unfortunately "IsKey" is always false for me
even though some columns are the primary keys. Why is that? Is there
something I'm doing wrong or something that I'm not doing? Some of the other
information in the _schemaTable such as "ColumnName" is correct for each of
the columns in the table. The following is the code sample: Thanks for help
in advance.
Tom.

System.Data.IDataReader reader;

this._Command.CommandText = "SELECT * FROM [" + tableName + "]";

reader = _Command.ExecuteReader(System.Data.CommandBehavior.SingleRow);
_schemaTable = reader.GetSchemaTable();
 
Tom,

By default Key Information is not provided in the schema table.
You must use

reader = _Command.ExecuteReader(CommandBehavior.KeyInfo);

Regards,

Deepak
[I Code, therefore I am]
 
Tom,

You might try calling ExecuteReader like this:

reader = _Command.ExecuteReader(CommandBehavior.SchemaOnly Or
CommandBehavior.KeyInfo)

Kerry Moorman
 
Back
Top