如何在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();
}
}
}

上面的说明是从建一个数据库到表到字段,可是我只要在表里建一个字段,数据库和表都已经存在了,代码怎么修改,或有什么别的方法.
...全文
556 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CXJust 2009-12-01
  • 打赏
  • 举报
回复
请问“ADOX”命名空间的程序集该如何引入
sonoffreedom 2009-11-18
  • 打赏
  • 举报
回复
帮顶



可以加我QQ 157864607,欢迎多多交流


本人代写各类。NET组件/软件,服务优价廉
古今多少事 2009-11-12
  • 打赏
  • 举报
回复
修改先删除再添加。
古今多少事 2009-11-12
  • 打赏
  • 举报
回复
SQL语句:
'添加
Alter Table 表名 Add Column 字段名 数据类型)
'删除
Alter Table 表名 Drop Column 字段名)
wuyq11 2009-11-12
  • 打赏
  • 举报
回复
table.Columns.Delete("");
table.Columns.Refresh();

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧