| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3946 人关注过本帖
标题:如何判断ACCESS数据库中表是否存在?
取消只看楼主 加入收藏
wwx024
Rank: 1
等 级:新手上路
帖 子:33
专家分:4
注 册:2008-6-15
收藏
 问题点数:0 回复次数:0 
如何判断ACCESS数据库中表是否存在?
我有动态创建一个数据库coldlead.mdb,然后创建一个表orderlist,第一次运行正常,第二次运行就报错:说表orderlist已存在。
我想首先判断一个表是否存在,如果不存在就创建,如果存在就不用创建。
//创建ACCESS表            
            ADOX.Table table = new ADOX.Table();
            table.Name = "orderList";
            ADOX.Column column = new ADOX.Column();
            column.ParentCatalog = cat;
            column.Name = "RecordId";
            column.Type = DataTypeEnum.adInteger;
            column.DefinedSize = 9;
            column.Properties["AutoIncrement"].Value = true;
            table.Columns.Append(column, DataTypeEnum.adInteger, 9);//增加一个自动增长的字段
            table.Keys.Append("FirstTablePrimaryKey", KeyTypeEnum.adKeyPrimary, column, null, null);//设置主键
            table.Columns.Append("Accept Order Date", DataTypeEnum.adDate, 0);//add a column of accept order date
            table.Columns.Append("Production Order", DataTypeEnum.adWChar,10);//add a column of Production Order
            table.Columns.Append("Product Spec",DataTypeEnum.adWChar,10);//add a column of the product spec
            table.Columns.Append("Product Unit",DataTypeEnum.adWChar,10);//add a loumun of the product unit
            table.Columns.Append("Product Number",DataTypeEnum.adInteger,3);//add a column of the product number
            table.Columns.Append("Delivery Date",DataTypeEnum.adDate,0);//add a column of the delivery date
            cat.Tables.Append(table);
            

            MessageBox.Show("数据库表:" + tableName + "已经创建成功!");
            cn.Close();  
            
            //connect the databank
            OleDbConnection myConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + Application.StartupPath + @"\ColdLead.mdb'");
            //insert data to the table            
            string myExecuteQuery = "insert into [orderList]([Accept Order Date],[Production Order],[Product Spec],[Product Unit],[Product Number],[Delivery Date])values(2008-10-10,'wwx','122ls/45r','gr',50,2008-11-20)";
            myConnection.Open();
            OleDbCommand myCommand=new OleDbCommand (myExecuteQuery,myConnection);      
            
            
            myCommand.ExecuteNonQuery();


            OleDbDataAdapter da = new OleDbDataAdapter("select * from orderList", myConnection);
            //control data with DataSet
            DataSet ds = new DataSet();
            da.Fill(ds);
            //show the data in the dataGridView
            dataGridView1.DataSource = ds.Tables[0].DefaultView;
            //close the databank connect
            myConnection.Close();
搜索更多相关主题的帖子: 数据库 中表 ACCESS 判断 
2008-10-29 09:13
快速回复:如何判断ACCESS数据库中表是否存在?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027707 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved