如何在adox中设置表列的AutoIncrement-property? [英] how to set the AutoIncrement-property of table column in adox?

查看:109
本文介绍了如何在adox中设置表列的AutoIncrement-property?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在标题中所解释的,我无法将属性设置为列:

as i explain in the title, i cant set the property to the column:

Catalog cat = new Catalog();
        Table tableCustomer = new Table();
        Table tableAddresses = new Table();

        try
        {                
            //Create the table Customer and it's fields. 
            tableCustomer.Name = "Customer";
            tableCustomer.Columns.Append("Customer_ID", ADOX.DataTypeEnum.adInteger);
            //column.ParentCatalog = cat;
            //column.Name = "Customer_ID";
            //column.Type = ADOX.DataTypeEnum.adInteger;
            //column.Properties["AutoIncrement"].Value = true;

            //tableCustomer.Columns.Append(column);

            tableCustomer.Keys.Append("PrimaryKEy", KeyTypeEnum.adKeyPrimary, "Customer_ID");
            tableCustomer.Columns["Customer_ID"].Properties["AutoIncrement"].Value = true;
            tableCustomer.Columns.Append("Name", ADOX.DataTypeEnum.adVarWChar, 50);
            tableCustomer.Columns.Append("Email", ADOX.DataTypeEnum.adVarWChar, 50);
            tableCustomer.Columns.Append("TelNumber", ADOX.DataTypeEnum.adVarWChar, 32);
            tableCustomer.Columns.Append("Fax", ADOX.DataTypeEnum.adVarWChar, 32);
            tableCustomer.Columns.Append("AdressCounter", ADOX.DataTypeEnum.adSmallInt);

            tableAddresses.Name = "Addresses";
            tableAddresses.Columns.Append("Address_ID", ADOX.DataTypeEnum.adInteger);
            tableAddresses.Keys.Append("PrimaryKEy", KeyTypeEnum.adKeyPrimary, "Address_ID");
            tableAddresses.Columns.Append("Customer_ID", ADOX.DataTypeEnum.adInteger);
            tableAddresses.Keys.Append("ForeignKey", KeyTypeEnum.adKeyForeign, "Customer_ID", "Customer", "Customer_ID");
            tableAddresses.Columns.Append("Street", ADOX.DataTypeEnum.adVarWChar, 50);
            tableAddresses.Columns.Append("PostalCode", ADOX.DataTypeEnum.adVarWChar, 10);
            tableAddresses.Columns.Append("City", ADOX.DataTypeEnum.adVarWChar, 50);

            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Application.StartupPath
                + "\\Customers.mdb" + "; Jet OLEDB:Engine Type=5");
            cat.Tables.Append(tableCustomer);
            cat.Tables.Append(tableAddresses);


            //Now Close the database
            ADODB.Connection con = cat.ActiveConnection as ADODB.Connection;
            if (con != null)
                con.Close();


            result = true;
        }
        catch (Exception ex)
        {
            result = false;
        }
        finally
        {
            if (!result)
            {
                ADODB.Connection con = cat.ActiveConnection as ADODB.Connection;
                if (con != null)
                    con.Close();
                File.Delete(Application.StartupPath + "\\Customers.mdb");
            }                 
        }
        cat = null;

我收到一个错误,在执行以下行后未找到对象:

i am getting an error, that the object in not found after executing the following line:

tableCustomer.Columns["Customer_ID"].Properties["AutoIncrement"].Value = true;

错误是找不到对象.但是在 vb 中的所有解决方案中,他们都像我写的那样解决了.我做错了什么?

the error is that the object is not found. but in all solutions in vb, they solve it like i wrote. what am i doing wrong?

推荐答案

您应该像在代码的注释行中那样添加 "Customer_ID" 列.根据 this源,您错过了为 Column 设置 ParentCatalog 属性.

You should add the "Customer_ID" column like you did in the commented lines of your code. According to this source, you missed to set the ParentCatalog property for the Column.

这篇关于如何在adox中设置表列的AutoIncrement-property?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆