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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Konrad

    changing column to autonumber

    Konrad, Jul 19, 2003, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    713
    Konrad
    Jul 20, 2003
  2. scj
    Replies:
    0
    Views:
    279
  3. Guest
    Replies:
    5
    Views:
    327
    Kevin Yu [MSFT]
    Nov 6, 2003
  4. Raymond Du

    How to determine if a DB column value is null?

    Raymond Du, Apr 10, 2004, in forum: Microsoft ADO .NET
    Replies:
    5
    Views:
    421
    Miha Markic [MVP C#]
    Apr 11, 2004
  5. Joe
    Replies:
    4
    Views:
    6,226
    Paul Clement
    Jun 7, 2004
  6. Marina
    Replies:
    1
    Views:
    283
    Kevin Yu [MSFT]
    Jun 30, 2004
  7. Guest

    Autonumber Column in Insert

    Guest, Feb 28, 2005, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    432
    Guest
    Mar 1, 2005
  8. David Eadie
    Replies:
    2
    Views:
    465
    David Eadie
    Apr 10, 2005
Loading...