HOW TO: Determine if Access column is an AutoNumber

Discussion in 'Microsoft ADO .NET' started by Guest, Feb 3, 2005.

  1. Guest

    Guest Guest

    In ADO.Net, how might one determine whether a column in an Access table is an
    AutoNumber type?

    Could this be accomplished using OleDbSchemaGuid. If so could you give an
    example.

    Thanks for the tip.
     
    Guest, Feb 3, 2005
    #1
    1. Advertisements

  2. Burton G. Wilkins wrote:
    > In ADO.Net, how might one determine whether a column in an Access table is an
    > AutoNumber type?
    >
    > Could this be accomplished using OleDbSchemaGuid. If so could you give an
    > example.


    No, use this trick:
    OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [" +
    tableName + "] WHERE 1=0", openConnection);

    DataTable tableSchema = adapter.FillSchema(new DataTable(),
    SchemaType.Source);

    for (int j = 0; j < tableSchema.Columns.Count; j++)
    {
    if(tableSchema.Columns[j].AutoIncrement)
    {
    // is identity
    }
    }

    Frans

    --
    ------------------------------------------------------------------------
    Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
    My .NET blog: http://weblogs.asp.net/fbouma
    Microsoft MVP (C#)
    ------------------------------------------------------------------------
     
    Frans Bouma [C# MVP], Feb 3, 2005
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    Thank you, Frans. You have provided a good trick indeed.

    "Frans Bouma [C# MVP]" wrote:

    > Burton G. Wilkins wrote:
    > > In ADO.Net, how might one determine whether a column in an Access table is an
    > > AutoNumber type?
    > >
    > > Could this be accomplished using OleDbSchemaGuid. If so could you give an
    > > example.

    >
    > No, use this trick:
    > OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [" +
    > tableName + "] WHERE 1=0", openConnection);
    >
    > DataTable tableSchema = adapter.FillSchema(new DataTable(),
    > SchemaType.Source);
    >
    > for (int j = 0; j < tableSchema.Columns.Count; j++)
    > {
    > if(tableSchema.Columns[j].AutoIncrement)
    > {
    > // is identity
    > }
    > }
    >
    > Frans
    >
    > --
    > ------------------------------------------------------------------------
    > Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
    > My .NET blog: http://weblogs.asp.net/fbouma
    > Microsoft MVP (C#)
    > ------------------------------------------------------------------------
    >
     
    Guest, Feb 3, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Konrad

    changing column to autonumber

    Konrad, Jul 19, 2003, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    601
    Konrad
    Jul 20, 2003
  2. scj
    Replies:
    0
    Views:
    189
  3. Guest
    Replies:
    5
    Views:
    255
    Kevin Yu [MSFT]
    Nov 6, 2003
  4. Guest

    Autonumber Column in Insert

    Guest, Feb 28, 2005, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    297
    Guest
    Mar 1, 2005
  5. David Eadie
    Replies:
    2
    Views:
    314
    David Eadie
    Apr 10, 2005
Loading...

Share This Page