Reputation: 3016
After adding a new column to a table in a Microsoft Access database, how can you set its Validation Rule and Validation Text?
My current workaround is a check constraint on the table.
The code uses System.Data.OleDb
classes from .NET Framework 1.1, and the database engine is Microsoft Jet 4.0 (it is a very old application).
Upvotes: 0
Views: 150
Reputation: 123419
You can use Jet DAO if you add the "Microsoft DAO 3.6 Object Library" COM reference to your .NET project. Then you can do something like this:
var dbEngine = new DAO.DBEngine();
DAO.Database db = dbEngine.OpenDatabase(@"C:\Users\Public\mdbTest.mdb");
DAO.TableDef tbd = db.TableDefs["rule"];
DAO.Field fld = tbd.Fields["rule_number"];
fld.ValidationRule = "<> 6";
fld.ValidationText = "There is NO rule 6!";
db.Close();
Upvotes: 2