我正在使用c#和数据库访问文档管理系统。
到目前为止,我创建了两个表:
项目表: 在这个表中有几个列,如“ProjectCode”,“ProjectManager”,“ProjectName”,...(ProjectCode是唯一的)
记录: 此表用于保存每个项目的记录,例如“文档编号”,“修订版”,“标题”,“DateReceived”,...
我的问题是: 每当我将新项目添加到“项目表”
时,是否可以为每个项目创建单独的“记录”表例如:如果我添加新的ProjectCode“A0002”,那么新的记录表将被创建为“RecordsA0002”
答案 0 :(得分:1)
// Only for demonstration purposes, no error checks:
// This code will only work as long as the table "Records002" does not exist
string id = "002";
// First create an new database if necessary
Catalog cat = OpenDatabase();
// Create a new table "Records" using ADOX ...
Table table = new Table();
table.Name = "Records" + id;
cat.Tables.Append(table);
// Add Column "RecordsID" with Autoincrement
ADOX.Column col = new Column();
col.Name = "RecordsID";
col.ParentCatalog = cat;
col.Type = ADOX.DataTypeEnum.adInteger;
col.Properties["Nullable"].Value = false;
col.Properties["AutoIncrement"].Value = true;
table.Columns.Append(col);
// Make "Records" the primary key
ADOX.Index index = new ADOX.Index();
index.PrimaryKey = true;
index.Name = "PK_RecordsID";
index.Columns.Append("RecordsID", table.Columns["RecordsID"].Type, table.Columns["RecordsID"].DefinedSize);
table.Indexes.Append(index);
MessageBox.Show("A new Data Table is successfully Created");