user2852283 user2852283 - 5 months ago 35
C# Question

Get AutoNumber column index in Ms Access 2010/2013

(first sorry for my English):

I want to temporarily change

column to
data type to import records from another database. After importing the records, I want to change it back to

My Problem:
I try to use the
property to check if this column is
and get its index so that I can change its datatype, but this property didn't work for me, it returned false for all columns.

I work with 2010/2013 Access database.

So I want to know what to do to get index of


You can use this approach

// Bogus query, we don't want any record, so add a always false condition
OleDbCommand cmd = new OleDbCommand("SELECT * FROM aTable where 1=2", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable test = new DataTable();
da.FillSchema(test, SchemaType.Source);
for(int x = 0; x < test.Columns.Count; x++)
    DataColumn dc = test.Columns[x];
    Console.WriteLine("ColName = " + dc.ColumnName + 
                      ", at index " + x +
                      " IsAutoIncrement:" + dc.AutoIncrement);