trying to do a primary key that is autoincrement. Here is the part for Thw ID in code.
Thanks for looking at this and helpping.
John
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileBinPath; (OleDbConnection connection = new OleDbConnection(connectionString)) Catalog catalog = new Catalog(); catalog.Create(connectionString); Table table = new Table(); table.Name = "Users"; DataColumn columnId = new DataColumn(); columnId.DataType = System.Type.GetType("System.Int32"); columnId.AutoIncrement = true; columnId.AutoIncrementSeed = 1; columnId.AutoIncrementStep = 1; columnId.AllowDBNull = false; Column nameCol = new Column(); nameCol.Name = "Name"; nameCol.Type = ADOX.DataTypeEnum.adVarWChar; nameCol.DefinedSize = 60; table.Columns.Append(columnId); table.Columns.Append(nameCol); catalog.Tables.Append(table); DataGridView1.DataSource = table;
Naimish MakwanaPosted Sep 30, 2024, 6:28 AM
Hi ,
It looks like you’re trying to create a table with an auto-incrementing primary key in C#. I noticed a few things that might need adjustment. Here’s a revised version of your code:
Key changes:
ADOX.Columninstead ofDataColumnfor defining the columns.AutoIncrement,Seed, andIncrementproperties directly on thecolumnId.Nullableproperty tofalsefor theIDcolumn.Thanks