ADOX多步OLE DB操作生成错误

时间:2010-07-26 19:59:51

标签: c# ms-access adox

我必须创建一个程序来关闭所有Unicode压缩以及访问数据库(.mdb)中的所有“允许零长度”。

关闭“允许零长度”的方法非常有效。但是,关闭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");
    }                      
}

1 个答案:

答案 0 :(得分:0)

您应该检查字符串中是否有没有相应UNICODE值的字符,这些通常可以在从MS Word等应用程序复制和粘贴文本时引入。具体而言,“智能报价”经常会引发问题。

另请参阅以下主题(尽管它是在C ++中)Discussion on ADOX Property Usage in C++

您是否能够遍历属性并显示其当前值?

相关问题