PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET HOW TO: Determine if Access column is an AutoNumber

Reply

HOW TO: Determine if Access column is an AutoNumber

 
Thread Tools Rate Thread
Old 03-02-2005, 05:39 PM   #1
=?Utf-8?B?QnVydG9uIEcuIFdpbGtpbnM=?=
Guest
 
Posts: n/a
Default HOW TO: Determine if Access column is an AutoNumber


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.
  Reply With Quote
Old 03-02-2005, 06:22 PM   #2
Frans Bouma [C# MVP]
Guest
 
Posts: n/a
Default Re: HOW TO: Determine if Access column is an AutoNumber

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#)
------------------------------------------------------------------------
  Reply With Quote
Old 03-02-2005, 07:07 PM   #3
=?Utf-8?B?QnVydG9uIEcuIFdpbGtpbnM=?=
Guest
 
Posts: n/a
Default Re: HOW TO: Determine if Access column is an AutoNumber

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#)
> ------------------------------------------------------------------------
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off