为什么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();
}