HOW TO: Determine if Access column is an AutoNumber

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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

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

--
 
Back
Top