Feature Post

Top

C#/ADOX: Modifying MS Access (MDB) database

How to add a composite (multiple column) primary key to an MS Access (MDB) database using ADOX and C#?

Try following code:

using ADOX;
Table filesTable = new Table();
filesTable.Name = “MyTable”;
filesTable.Columns.Append(“Serial”, DataTypeEnum.adVarWChar, 100);
filesTable.Columns.Append(“Name”, DataTypeEnum.adVarWChar, 250);
filesTable.Columns.Append(“Name2”, DataTypeEnum.adVarWChar, 250);
filesTable.Columns.Append(“Phone”, DataTypeEnum.adVarWChar, 200);

filesTable.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary,
“Serial”, null, null);
filesTable.Keys["PrimaryKey"].Columns.Append(“Name”,
DataTypeEnum.adVarWChar, 250);
filesTable.Keys["PrimaryKey"].Columns.Append(“Name2”,
DataTypeEnum.adVarWChar, 250);
catalog.Tables.Append(filesTable);



How to add a boolean column in MS Access (MDB) database using C#/ADOX?
ADOX.Table theTable = new ADOX.Table();
theTable.Name = "MyTable";


ADOX.Column theCol=new ADOX.Column();
theCol.Name="MyColumn";
theCol.Type=ADOX.DataTypeEnum.adBoolean;

theTable.Columns.Append(theCol,
ADOX.DataTypeEnum.adBoolean,
System.Reflection.Missing.Value);