none
Autoincrement property RRS feed

  • Question

  • How do I create an auto increment column in a MS Access db using ADOX.column class in Visual C#?

    The datatype that supports creating an AutoNumber column is ADOX.DataTypeEnum.adInteger. However, I need to set the Autoincrement property to true but i can't figure out how to?
    Thursday, June 28, 2007 4:52 PM

Answers

  • Anuraj,
      I figured out the problem I was having. Actually I wanted to create a column that is an auto increment column in the database. Thus, it didn't help me to set the AutoIncrementSeed and Step for the data column.
      What worked for me is the following:

    ADOX.Column column = new ADOX.Column();
    column.Name = "RecordNumber";
    column.Type = ADOX.DataTypeEnum.adInteger;
    column.ParentCatalog = cat;
    column.Properties["AutoIncrement"].Value = true;
    table.Columns.Append(column, type, size);

    I was missing setting the ParentCatalog to the catalog I was using. This helped me to create an AutoIncrement column in the MS access DB. Thanks your help though.

    Awesomo
    Thursday, June 28, 2007 10:19 PM

All replies

  • Hi Awesomo

    Did you checked DataColumn.AutoIncrementSeed and DataColumn.AutoIncrementStep properties?

     

    Anuraj

    Thursday, June 28, 2007 9:33 PM
  • Anuraj,
      I figured out the problem I was having. Actually I wanted to create a column that is an auto increment column in the database. Thus, it didn't help me to set the AutoIncrementSeed and Step for the data column.
      What worked for me is the following:

    ADOX.Column column = new ADOX.Column();
    column.Name = "RecordNumber";
    column.Type = ADOX.DataTypeEnum.adInteger;
    column.ParentCatalog = cat;
    column.Properties["AutoIncrement"].Value = true;
    table.Columns.Append(column, type, size);

    I was missing setting the ParentCatalog to the catalog I was using. This helped me to create an AutoIncrement column in the MS access DB. Thanks your help though.

    Awesomo
    Thursday, June 28, 2007 10:19 PM