标题:为什么ACCESS数据库中表没有了?
只看楼主
wwx024
Rank: 1
等 级:新手上路
帖 子:33
专家分:4
注 册:2008-6-15
 问题点数:0 回复次数:3 
为什么ACCESS数据库中表没有了?
连接access数据库coldlead.mdb,里面有一个表orderlist,运行程序后,创建一个其他的表,表orderlist就没有了。不知道为什么?
代码:
private void enterButton_Click(object sender, EventArgs e)
        {           
            //instance a connect
            ADOX.CatalogClass cat = new ADOX.CatalogClass();
            ADODB.Connection cn = new ADODB.Connection();
            //open the databank that has foundation
            cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Application.StartupPath + @"\ColdLead.mdb'", null, null, -1);
            cat.ActiveConnection = cn;
     
            //creat a table
            string name = productionOrderTextBox.Text;
            ADOX.Table table = new ADOX.Table();
            table.Name = name;
            ADOX.Column column1 = new ADOX.Column();
            column1.ParentCatalog = cat;
            column1.Name = "RecordId";
            column1.Type = DataTypeEnum.adInteger;
            column1.DefinedSize = 9;
            column1.Properties["AutoIncrement"].Value = true;
            table.Columns.Append(column1, DataTypeEnum.adInteger, 9);//增加一个自动增长的字段
            table.Keys.Append("FirstTablePrimaryKey", KeyTypeEnum.adKeyPrimary, column1, null, null);//设置主键
            table.Columns.Append("Accept Order Date", DataTypeEnum.adDate, 20);//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, 20);//add a column of the delivery date
            cat.Tables.Append(table);

            MessageBox.Show("数据库表:" + "name" + "已经创建成功!");
            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 ,'year','122ls/45r','gr',50,2008-11-20)";
            myConnection.Open();
            OleDbCommand myCommand=new OleDbCommand (myExecuteQuery,myConnection);            
            
            //myCommand.Connection.Open();
            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();            
            
            //close the form2            
            form2.Close();            
        }
搜索更多相关主题的帖子: 数据库 中表 ACCESS 
2008-10-29 19:26
wwx024
Rank: 1
等 级:新手上路
帖 子:33
专家分:4
注 册:2008-6-15
得分:0 
2008-10-29 20:39
wwx024
Rank: 1
等 级:新手上路
帖 子:33
专家分:4
注 册:2008-6-15
得分:0 
没人知道?
2008-10-30 08:45
ghl2312
Rank: 4
等 级:业余侠客
威 望:2
帖 子:208
专家分:226
注 册:2008-7-10
得分:0 
被你的代码吓着了~
2008-10-30 09:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-241361-1-1.html




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

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