"Claudia Fong" wrote...
In my old table DEP2004, I have one field's property allow zero length
is YES, but after creating the new table DEP2005, this property change
to NO. It means it won't allow zero lenght.. How can I change this
property in C#?
My database is stored in Access.
Could someone know how should I do?
It's a bit tricky, but this method should work.
It worked for me when I tried... ;-)
You need to use some extra dll:s, one is straightforward, adodb.dll.
The other one is a COM-dll. If you're using VS.NET, you'll find it in the
COM-list as
Microsoft ADO Ext 2.8 for DDL and security
...which will be imported to your directory as interop.adox.dll
Anyway, here's the code:
private static void SetColumnAllowZeroLength(
string cnstring, string tablename, string columnname)
{
// open connection
ADODB.ConnectionClass conn = new ADODB.ConnectionClass();
conn.Open(cnstring, "", "", 0 );
// Create a catalog
ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.ActiveConnection = conn;
// fetch the table
ADOX.Table table = cat.Tables[tablename];
// fetch the column
ADOX.Column col = table.Columns[columnname];
// fetch the property and set it
ADOX.Property prop = col.Properties["Jet OLEDB:Allow Zero Length"];
prop.Value = true;
// finish up
col = null;
cat = null;
conn.Close();
conn = null;
}
// Bjorn A