HOW TO: Determine if Access column is an AutoNumber

G

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.
 
F

Frans Bouma [C# MVP]

Burton said:
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

--
 
G

Guest

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

Frans Bouma said:
Burton said:
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

--
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top