C# 使用ADOX创建access db时的数字字段类型给了我COMExceptions
我正在尝试使用ADOX名称空间创建Access DB 当我为测试目的将所有字段定义为ADOX.DataTypeEnum.adVarWChar时,一切都很好,但现在我正在尝试定义 整数或十进制(数字类型)和我的代码不再工作 我得到的例外是一个恶性循环 adInteger引发无效的类型异常, adDecimal引发无效的类型异常, adNumeric抛出无效精度异常 我找不到定义数字字段的正确方法的单一来源C# 使用ADOX创建access db时的数字字段类型给了我COMExceptions,c#,ms-access,com,adox,C#,Ms Access,Com,Adox,我正在尝试使用ADOX名称空间创建Access DB 当我为测试目的将所有字段定义为ADOX.DataTypeEnum.adVarWChar时,一切都很好,但现在我正在尝试定义 整数或十进制(数字类型)和我的代码不再工作 我得到的例外是一个恶性循环 adInteger引发无效的类型异常, adDecimal引发无效的类型异常, adNumeric抛出无效精度异常 我找不到定义数字字段的正确方法的单一来源 ADOX.Table table1 = new ADOX.Table();
ADOX.Table table1 = new ADOX.Table();
ADOX.Key tableKey1 = new Key();
ADOX.Column idColumn1 = new Column();
// Define column with AutoIncrement features
idColumn1.Name = "ID";
idColumn1.Type = ADOX.DataTypeEnum.adInteger;
// Set ID as primary key
tableKey1.Name = "Primary Key";
tableKey1.Columns.Append("ID");
tableKey1.Type = KeyTypeEnum.adKeyPrimary;
//Create the table and it's fields.
table1.Name = "Artikli";
table1.Columns.Append(idColumn1);
table1.Columns.Append("FLAG", ADOX.DataTypeEnum.adVarWChar, 50);
table1.Columns.Append("SIFRA", ADOX.DataTypeEnum.adInteger);
table1.Columns.Append("BARKOD", ADOX.DataTypeEnum.adVarWChar, 50);
table1.Columns.Append("NAZIV", ADOX.DataTypeEnum.adVarWChar, 50);
table1.Columns.Append("JM", ADOX.DataTypeEnum.adVarWChar, 50);
table1.Columns.Append("TB", ADOX.DataTypeEnum.adNumeric);
table1.Columns.Append("MPC", ADOX.DataTypeEnum.adNumeric);
table1.Columns.Append("VPC", ADOX.DataTypeEnum.adNumeric);
table1.Columns.Append("NC", ADOX.DataTypeEnum.adNumeric);
table1.Columns.Append("ZALIHE", ADOX.DataTypeEnum.adInteger);
table1.Columns.Append("RG", ADOX.DataTypeEnum.adVarWChar, 50);
table1.Columns.Append("KALO", ADOX.DataTypeEnum.adInteger);
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fileName + "; Jet OLEDB:Engine Type=5");
// Must create database file before applying autonumber to column
idColumn.ParentCatalog = cat;
idColumn.Properties["AutoIncrement"].Value = true;
idColumn1.ParentCatalog = cat;
idColumn1.Properties["AutoIncrement"].Value = true;
idColumn2.ParentCatalog = cat;
idColumn2.Properties["AutoIncrement"].Value = true;
idColumn3.ParentCatalog = cat;
idColumn3.Properties["AutoIncrement"].Value = true;
idColumn4.ParentCatalog = cat;
idColumn4.Properties["AutoIncrement"].Value = true;
idColumn5.ParentCatalog = cat;
idColumn5.Properties["AutoIncrement"].Value = true;
idColumn6.ParentCatalog = cat;
idColumn6.Properties["AutoIncrement"].Value = true;
idColumn7.ParentCatalog = cat;
idColumn7.Properties["AutoIncrement"].Value = true;
idColumn8.ParentCatalog = cat;
idColumn8.Properties["AutoIncrement"].Value = true;
cat.Tables.Append(table);
cat.Tables.Append(table1); // throws exception
cat.Tables.Append(table2);
cat.Tables.Append(table3);
cat.Tables.Append(table4);
cat.Tables.Append(table5);
cat.Tables.Append(table6);
cat.Tables.Append(table7);
cat.Tables.Append(table8);
结果是我必须为数字类型定义精度。。。 这是语法,但如果有人知道更简单的语法,请分享
ADOX.Column numeric = new Column();
numeric.Name = "TB";
numeric.Type = ADOX.DataTypeEnum.adNumeric;
numeric.Precision = 17;
table1.Columns.Append(numeric);
结果是我必须为数字类型定义精度。。。 这是语法,但如果有人知道更简单的语法,请分享
ADOX.Column numeric = new Column();
numeric.Name = "TB";
numeric.Type = ADOX.DataTypeEnum.adNumeric;
numeric.Precision = 17;
table1.Columns.Append(numeric);
好的,我找到了以下信息:*在Microsoft Jet 4.0和Microsoft SQL Server 7.0中使用adNumeric数据类型时,必须设置精度。。。现在正在研究如何设置精度-我将发布更新OK我发现了以下信息:*当您在Microsoft Jet 4.0和Microsoft SQL Server 7.0中使用adNumeric数据类型时,必须设置精度。。。正在研究如何设置精度-我将发布更新