如何在Access表里增加修改删除字段
wzckr 2009-11-12 08:07:58 在网上找了一文章:
using System;
using System.Collections.Generic;
using System.Text;
using ADOX;
namespace ADOXCreateTable
...{
class Program
...{
static void Main(string[] args)
...{
string dbName = "D:\DataBase\FirstCatalog.mdb";
ADOX.CatalogClass catlog = new ADOX.CatalogClass();
catlog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbName + ";"+"Jet OLEDB:Engine Type=5");
ADOX.TableClass table = new ADOX.TableClass();
table.ParentCatalog = catlog;
table.Name = "FirstTable";
//StuId Column(AutoIncrement )
ADOX.ColumnClass col1 = new ADOX.ColumnClass();
col1.ParentCatalog = catlog;
col1.Type = ADOX.DataTypeEnum.adInteger;
col1.Name = "StuId";
col1.Properties["Jet OLEDB:Allow Zero Length"].Value = false;
col1.Properties["AutoIncrement"].Value = true;
//Name Column
ADOX.ColumnClass col2 = new ADOX.ColumnClass();
col2.ParentCatalog = catlog;
col2.Name = "StuName";
col2.Properties["Jet OLEDB:Allow Zero Length"].Value = false;
//Age Column
ADOX.ColumnClass col3 = new ADOX.ColumnClass();
col3.ParentCatalog = catlog;
col3.Name = "Stuage";
col3.Type = DataTypeEnum.adDouble;
col3.Properties["Jet OLEDB:Allow Zero Length"].Value = false;
// Primary
table.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "StuId", "", "");
table.Columns.Append(col1, ADOX.DataTypeEnum.adInteger, 0);
table.Columns.Append(col3, ADOX.DataTypeEnum.adDouble, 666);
table.Columns.Append(col2, ADOX.DataTypeEnum.adVarChar, 25);
catlog.Tables.Append(table);
System.Runtime.InteropServices.Marshal.ReleaseComObject(table);
System.Runtime.InteropServices.Marshal.ReleaseComObject(catlog);
table = null;
catlog = null;
GC.WaitForPendingFinalizers();
GC.Collect();
}
}
}
上面的说明是从建一个数据库到表到字段,可是我只要在表里建一个字段,数据库和表都已经存在了,代码怎么修改,或有什么别的方法.