Determing which column is identity column

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

Hi,
I am querying the database and sticking the results into a datatable.
It would be helpful though if I could determine programmatically which
column in that datatable is the identity column (if there is one). Is
there a way to do this?
 
Hi Doug,

I guess you are using .net 1.x.
One of the options is to use OleDbConnection.GetOleDbSchemaTable. The other
option would be to use database specific ddl queries.
 
In addition to Miha's comments, once the datatable is filled I think y ou
can loop through the datacolumns and check the Autoincrement property - if
it's true, that's it.
 
AutoIncrement doesn't work because it's a property of the dataset
itself and not the data from the database that is in the dataset.

I am using version 1.1.

I am trying to use the Data Access Block that Microsoft provides and so
in my actual app, I don't have access to the connection object (it's
open source code so I could go into it and manipulate it, but that's a
last step for me). I was just wondering if some property of the
DataSet would properly reflect that a column is a identity column.
 
Doug - the adapter builds the schema for the datatable based on the db if
you don't specify it. I thought Autoincrement came back - lemme double check
it.

I'm afraid you're going to have to modify the code though if you want to
use the GetSchemaTable or similar approach
 
Back
Top