PC Review


Reply
Thread Tools Rate Thread

HOW TO: Determine if Access column is an AutoNumber

 
 
=?Utf-8?B?QnVydG9uIEcuIFdpbGtpbnM=?=
Guest
Posts: n/a
 
      3rd Feb 2005
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
 
 
 
 
Frans Bouma [C# MVP]
Guest
Posts: n/a
 
      3rd Feb 2005
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
 
 
 
 
=?Utf-8?B?QnVydG9uIEcuIFdpbGtpbnM=?=
Guest
Posts: n/a
 
      3rd Feb 2005
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Sub Autonumber that re-assigns autonumber to each data groupin a sorted field. Junwenren Microsoft Access 1 4th Oct 2008 05:30 AM
Adding autonumber to a non autonumber field don Microsoft Access 2 22nd Apr 2008 05:00 PM
PK - To AutoNumber or Not To AutoNumber - That is the Question! :- =?Utf-8?B?ZGVl?= Microsoft Access Database Table Design 40 9th Aug 2007 08:52 AM
code to autonumber form ID without using autonumber datatype reservedbcreater Microsoft Access Form Coding 4 27th Jan 2005 04:56 PM
AutoNumber field does not contain "(AutoNumber)" when adding a record Keith Microsoft Access Forms 3 12th Nov 2003 05:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:40 AM.