How to identify Auto Increment fient in Access database

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

I am trying to identify which field in Access database table is an
Auto_Incement field, here's the code I am using, but I do not know how to
tell if the field is Auto_Increment type of field. Does anyone has a way to
do that?

Thank You

Peter



DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
new Object[] { null, null, tableName });
DataRow row;

for (int i = 0; i < schemaTable.Rows.Count; i++)
{
col = new Column();

row = schemaTable.Rows;
col.Name = row["COLUMN_NAME"].ToString();
int FlagsPos = schemaTable.Columns.IndexOf("COLUMN_FLAGS");
int Flags = Convert.ToInt32(row.ItemArray[FlagsPos]);
col.Type = Convert.ToInt32(row["DATA_TYPE"]);
col.OrdinalPosition = Convert.ToInt32(row["ORDINAL_POSITION"]);
//
// this does not work, it identifies any numeric field as 3 and Flags =
90
//
if(col.Type == 3 && Flags == 90)
col.AutoIncrement = true;

columns.Add(col);
}
 
Hello Peter,

We cannot know if a column is auto increment type from the
GetOleDbSchemaTable() method. As we discussed in another thread you post,
there are two ways to retrieve the schema information of Access,

1.GetOleDbSchemaTable()
2.ADOX

It is a disadvantage of the GetOleDbSchemaTable that we cannot detect if a
column is auto increment. ADO.NET just does not provide such support here
for OleDb. If that schema information is really necessary, we need to use
the ADOX approach as I suggested,

Please read the following discussion which is originally posted in the
newsgroup,
http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-ado-net/4589/Detect-auton
umbered-field-in-MS-Access

Please let me know if you need any future help on this! Thanks and have a
nice day!


Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
Back
Top