Re: How to determine if a table has a column that is autoincrement(Identity)?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Paul Clement (UseAdddressAtEndofMessage_at_swspectrum.com)
Date: 06/03/04


Date: Thu, 03 Jun 2004 09:48:06 -0500

On 2 Jun 2004 20:22:11 -0700, anon03@comcast.net (Joe) wrote:

¤ Hi All,
¤
¤ I am trying to find out how to determine if a table that I am
¤ working with contains a column that is an identity column (ie,
¤ has autoincrement set to true). I am working in C# and I'm
¤ already using the GetOleDbSchemaTable method to get the schema
¤ for the table I am interested in. However, this DataTable that
¤ I get back does give me the names of the columns but it does
¤ not tell me if a column is an identity column, or at the very
¤ least I don't know where to look for it in the Datatable. This
¤ is the call I am using:
¤
¤ DataTable dtCols = conn.GetOleDbSchemaTable(
¤ OleDbSchemaGuid.Columns,
¤ new Object[]{null, null, sTableName, null});
¤
¤ Now I've seen posts and visted websites that say you can get
¤ the autoincrement/identity flag by accessing the Columns data
¤ member as such:
¤
¤ dtCols.Columns[i].AutoIncrement
¤
¤ Now, although this flag is there, it seems to be associated
¤ with some meta-data column. In fact, all of the Columns that
¤ are in the DataTable(dtCols, the table that I get from the
¤ call above) seem to be associated with the table's meta-data
¤ (like, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME). Its the Rows
¤ data member that contains information on the columns of the
¤ table but I can't find any reference to the autoincrement or
¤ identity flag. I was hoping it would be in this DataTable
¤ since I could make one function call and get all I need.
¤
¤ Can someone please tell me how I can programatically get this
¤ flag or tell me where to find it? Thanks in advance.

An auto increment column is implemented differently depending upon the type of database you are
working with. It isn't exposed via GetOleDbSchema.

As Miha mentioned, we would have to know what the database product is that you are using.

Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)



Relevant Pages

  • Re: How to determine if a table has a column that is autoincrement(Identity)?
    ... "Joe" wrote in message ... > working with contains a column that is an identity column (ie, ... > has autoincrement set to true). ... > the autoincrement/identity flag by accessing the Columns data ...
    (microsoft.public.dotnet.framework.adonet)
  • How to determine if a table has a column that is autoincrement(Identity)?
    ... working with contains a column that is an identity column (ie, ... has autoincrement set to true). ... Now, although this flag is there, it seems to be associated ... with some meta-data column. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Determing which column is identity column
    ... 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 trying to use the Data Access Block that Microsoft provides and so ... DataSet would properly reflect that a column is a identity column. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Determing which column is identity column
    ... I thought Autoincrement came back - lemme double check ... > I am trying to use the Data Access Block that Microsoft provides and so ... > open source code so I could go into it and manipulate it, ... > DataSet would properly reflect that a column is a identity column. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Trigger with aggregate possible ?
    ... That would have been my first choice, ... has a unique IDENTITY column. ... >How about using an IDENTITY column to autoincrement the value? ...
    (microsoft.public.sqlserver.programming)