我必须制作一个程序来关闭访问数据库 (.mdb) 中的所有 Unicode 压缩和所有“允许零长度”。
关闭允许零长度的方法效果很好。但是关闭Unicode压缩的方法根本不起作用,返回如下异常:
多步 OLE DB 操作产生错误。检查每个 OLE DB 状态值(如果可用)。没有做任何工作。
关于如何解决这个问题的任何线索?
private void TurnOffUnicodeCompressionInField(ADOX.CatalogClass catalogClass, String tableName, String field)
{
ADOX.Column column = catalogClass.Tables[tableName].Columns[field];
ADOX.Property prop = column.Properties["Jet OLEDB:Compressed UNICODE Strings"];
prop.Value = true;
}
private void TurnOffAllowZeroLengthInAllFields(ADOX.CatalogClass catalogClass, String tableName)
{
foreach (ADOX.Column column in catalogClass.Tables[tableName].Columns)
column.Properties["Jet OLEDB:Allow Zero Length"].Value = false;
}
private void MyButton_Click(object sender, EventArgs e)
{
String filePath = "";
OpenFileDialog ofd = new OpenFileDialog();
DialogResult result = ofd.ShowDialog();
if (result == DialogResult.OK)
{
filePath = ofd.FileName;
ADOX.CatalogClass catDatabase = new ADOX.CatalogClass();
catDatabase.let_ActiveConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath);
// SoftwareTable
TurnOffAllowZeroLengthInAllFields(catDatabase,"Software");
TurnOffUnicodeCompressionInField(catDatabase, "Software", "Description");
TurnOffUnicodeCompressionInField(catDatabase, "Software", "Name");
}
}