使用 OLEDB 连接的 MS ACCESS 2003 中的分组对象错误

发布于 2024-12-12 17:42:35 字数 1560 浏览 4 评论 0原文

我有一个 MS ACCESS 2003 数据库,其中有一个表“TABLEA”。

然后我使用 OLEDB 连接并创建一个表,然后以编程方式填充数据,如下所示:

 string create_table_script = @" CREATE TABLE [" + Path.GetFileNameWithoutExtension(filename) + @"](
                        [AutoID] COUNTER PRIMARY KEY  ,
                        [CAS] text(255) ,
                        [Listed French Ingredient No] text(255) ,
                        [Name] text(255) ,
                        [GC] text(20) ,
                        [Grp_Code] text(10) ,
                        [Galsyn] Memo ,
                        [Notes LCN] text(255) ,
                        [Notes LFIN] text(255) ,
                        [%w/w] text(255) )";



        string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + fullpath + ";" + " User Id=admin; Password=";

        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            OleDbCommand SelectCommand = new OleDbCommand(create_table_script, connection);

            connection.Open();

            try
            {
                SelectCommand.ExecuteNonQuery();

            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                connection.Close();
            }

        }

填充此表后,

每当我打开此访问数据库时,我只会收到此消息一次

“31613 您已选择“表和相关视图”作为分组方式数据库中的对象。Access 需要更新有关对象依赖性的信息来创建组,这对于大型数据库来说需要一些时间。是否继续?”

我不知道我错在哪里。我为此目瞪口呆,但没有得到任何好处。 我认为创建表中有一些问题

任何帮助都是值得赞赏的。

I have a MS ACCESS 2003 datatbase that have one table in it "TABLEA".

Then I use OLEDB connection and create a table and then fill the data programatically as:

 string create_table_script = @" CREATE TABLE [" + Path.GetFileNameWithoutExtension(filename) + @"](
                        [AutoID] COUNTER PRIMARY KEY  ,
                        [CAS] text(255) ,
                        [Listed French Ingredient No] text(255) ,
                        [Name] text(255) ,
                        [GC] text(20) ,
                        [Grp_Code] text(10) ,
                        [Galsyn] Memo ,
                        [Notes LCN] text(255) ,
                        [Notes LFIN] text(255) ,
                        [%w/w] text(255) )";



        string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + fullpath + ";" + " User Id=admin; Password=";

        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            OleDbCommand SelectCommand = new OleDbCommand(create_table_script, connection);

            connection.Open();

            try
            {
                SelectCommand.ExecuteNonQuery();

            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                connection.Close();
            }

        }

After filling this table,

I get this message only once whenever i open this access datatbase

"31613 You have selected "Tables and Related Views" as the way to group objects in the database. Access needs to update information on object dependencies to create the groups. This will take some time for large databases.Do you want to continue?"

I don't know where i am wrong. I goggled it for this but does not get any benefit.
I think there is some thing wrong in create table

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╄→承喏 2024-12-19 17:42:36

这是使用 C# 代码创建 MS Access 表的最佳方法。

public string con_string;       
public OleDbConnection My_conn;// = new OleDbConnection();
public OleDbDataAdapter My_ada;
public OleDbCommand cmd;
public DataSet myds;// = new DataSet();
public void Make_Connention()
    {


        {
            con_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =";
            con_string += AppDomain.CurrentDomain.BaseDirectory.ToString() + "<yourdb>.mdb";
        }            
        My_conn = new OleDbConnection();
        My_conn.ConnectionString = con_string;
    }
public void IF_EXISTS_DELETE_AND_CREATE()
    {
        try
        {
            Make_Connention();
            string cn = con_string;
            OleDbConnection connection = new OleDbConnection(cn);
            object[] objArrRestrict;
            objArrRestrict = new object[] { null, null, null, "TABLE" };
            connection.Open();
            DataTable schemaTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, objArrRestrict);
            connection.Close();
            string[] list;
            if (schemaTable.Rows.Count > 0)
            {
                list = new string[schemaTable.Rows.Count];
                int i = 0;
                foreach (DataRow row in schemaTable.Rows)
                {
                    list[i++] = row["TABLE_NAME"].ToString();
                }
                for (i = 0; i < list.Length; i++)
                {
                    if (list[i] == "TEMP")
                    {
                        string deletedl = "DROP TABLE TEMP";
                        using (OleDbConnection conn = new OleDbConnection(cn))
                        {
                            using (OleDbCommand cmd = new OleDbCommand(deletedl, conn))
                            {

                                conn.Open();
                                cmd.ExecuteNonQuery();
                                conn.Close();
                            }
                        }
                        break;
                    }
                }
            }
            string ddl = "CREATE TABLE TEMP (ID COUNTER,USERID INTEGER NOT NULL,[ADATE] TEXT(20), [ATIME] TEXT(20))";
            using (OleDbConnection conn = new OleDbConnection(cn))
            {
                using (OleDbCommand cmd = new OleDbCommand(ddl, conn))
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
        }
        catch (System.Exception e)
        {
            string ex = e.Message;
        }
    }

This is the Best Way to Create Table of MS Access using C# code.

public string con_string;       
public OleDbConnection My_conn;// = new OleDbConnection();
public OleDbDataAdapter My_ada;
public OleDbCommand cmd;
public DataSet myds;// = new DataSet();
public void Make_Connention()
    {


        {
            con_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =";
            con_string += AppDomain.CurrentDomain.BaseDirectory.ToString() + "<yourdb>.mdb";
        }            
        My_conn = new OleDbConnection();
        My_conn.ConnectionString = con_string;
    }
public void IF_EXISTS_DELETE_AND_CREATE()
    {
        try
        {
            Make_Connention();
            string cn = con_string;
            OleDbConnection connection = new OleDbConnection(cn);
            object[] objArrRestrict;
            objArrRestrict = new object[] { null, null, null, "TABLE" };
            connection.Open();
            DataTable schemaTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, objArrRestrict);
            connection.Close();
            string[] list;
            if (schemaTable.Rows.Count > 0)
            {
                list = new string[schemaTable.Rows.Count];
                int i = 0;
                foreach (DataRow row in schemaTable.Rows)
                {
                    list[i++] = row["TABLE_NAME"].ToString();
                }
                for (i = 0; i < list.Length; i++)
                {
                    if (list[i] == "TEMP")
                    {
                        string deletedl = "DROP TABLE TEMP";
                        using (OleDbConnection conn = new OleDbConnection(cn))
                        {
                            using (OleDbCommand cmd = new OleDbCommand(deletedl, conn))
                            {

                                conn.Open();
                                cmd.ExecuteNonQuery();
                                conn.Close();
                            }
                        }
                        break;
                    }
                }
            }
            string ddl = "CREATE TABLE TEMP (ID COUNTER,USERID INTEGER NOT NULL,[ADATE] TEXT(20), [ATIME] TEXT(20))";
            using (OleDbConnection conn = new OleDbConnection(cn))
            {
                using (OleDbCommand cmd = new OleDbCommand(ddl, conn))
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
        }
        catch (System.Exception e)
        {
            string ex = e.Message;
        }
    }
如此安好 2024-12-19 17:42:36

这是有关“导航窗格(快门栏)”中导航的访问问题,与您创建表的方式无关。您可以安全地忽略此问题,因为它是特定于 Access 的且与 OleDb 无关

This is an Access issue regarding navigation in the "Navigation Pane (Shutter Bar)" and has nothing to do with the way you are creating the table. You can safely ignore this issue because it is Access specific and not related to OleDb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文