J
Jason Kendall
I've got a program that needs to work with the schema of tables
mostly. I recently decided to extend it to be able to work with views
as well. I discovered that the DataReader's GetSchemaTable() method
returns more columns than are actually defined for the view.
The problem appears to be the KeyInfo commandbehavior. When I pass
one of the other behaviors, I don't get the extra columns, all of
which are the primary keys for tables joined into the view for which I
chose not to return their keys. When I use any of the other
CommandBehavior values I don't get details about the schema such as
whether a column is a primary key.
My app heavily relies on the format of the Schema DataTable so what I
would like, in a perfect world, is either:
1) Help on how to use the existing code to get the details of the
schema for only the columns I explicitly defined in my views.
2) SQL that pulls directly from the system tables which returns
columns containing the same information as that found in the DataTable
returned by GetSchemaTable.
---- Code Snippet ----------------
lcCmd = New SqlCommand(SQLString, lcConn)
lcDR = lcCmd.ExecuteReader(CommandBehavior.KeyInfo)
Return lcDR.GetSchemaTable()
-------------------------------------------
Any help would be greatly appreciated. If there's an online resource
that goes into details on this, you can just point me to that.
The biggest problem I've had building this SQL myself is telling
whether a given column is part of the Primary Key. I saw how to use
the syscolumns.status to tell if the column is an Identity, but not
all of my keys are Identity columns.
Thanks!
mostly. I recently decided to extend it to be able to work with views
as well. I discovered that the DataReader's GetSchemaTable() method
returns more columns than are actually defined for the view.
The problem appears to be the KeyInfo commandbehavior. When I pass
one of the other behaviors, I don't get the extra columns, all of
which are the primary keys for tables joined into the view for which I
chose not to return their keys. When I use any of the other
CommandBehavior values I don't get details about the schema such as
whether a column is a primary key.
My app heavily relies on the format of the Schema DataTable so what I
would like, in a perfect world, is either:
1) Help on how to use the existing code to get the details of the
schema for only the columns I explicitly defined in my views.
2) SQL that pulls directly from the system tables which returns
columns containing the same information as that found in the DataTable
returned by GetSchemaTable.
---- Code Snippet ----------------
lcCmd = New SqlCommand(SQLString, lcConn)
lcDR = lcCmd.ExecuteReader(CommandBehavior.KeyInfo)
Return lcDR.GetSchemaTable()
-------------------------------------------
Any help would be greatly appreciated. If there's an online resource
that goes into details on this, you can just point me to that.
The biggest problem I've had building this SQL myself is telling
whether a given column is part of the Primary Key. I saw how to use
the syscolumns.status to tell if the column is an Identity, but not
all of my keys are Identity columns.
Thanks!