Домой Access Create Access DB (v2): Справочник по C#

Create Access DB (v2): Справочник по C#

332
0


DirectoryInfo di;
ADOX.CatalogClass cat;
Table tbl;
Index primKeyIdx;

di = new DirectoryInfo(path);
if (!di.Exists)
di.Create();

cat = new ADOX.CatalogClass();

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + di.FullName + "\" + dbName + dbExt +
";Jet OLEDB:Engine Type=5"); // Engine Type = 4 for Access 97, 5 for Access 2000,2003 format

#region Create Table 'Info'
// Create instance of Table object.
tbl = new Table();

tbl.Name = "Info";
tbl.Columns.Append("Info_dbID", ADOX.DataTypeEnum.adInteger, 8);
tbl.Columns.Append("Info_Key", ADOX.DataTypeEnum.adVarWChar, 20);
tbl.Columns.Append("Info_Value", ADOX.DataTypeEnum.adVarWChar, 50);

// Set primary key columns to use auto increment
tbl.Columns[0].ParentCatalog = cat;
tbl.Columns[0].Properties["Autoincrement"].Value = true;
#endregion

#region Add primary key
// Append the table to catalog.
cat.Tables.Append((object)tbl);

// Create the primary key column with unique values.
primKeyIdx = new Index();
primKeyIdx.Name = "Info_dbID";
primKeyIdx.Unique = true;
primKeyIdx.PrimaryKey = true;
primKeyIdx.Columns.Append("Info_dbID", ADOX.DataTypeEnum.adInteger, 8);

// Append the index to table.
tbl.Indexes.Append((object)primKeyIdx, null);
#endregion

// Reset Variables
tbl = null; primKeyIdx = null;

// Reset Connection
cat.ActiveConnection = null;

Взято с http://forums.devshed.com

ЧИТАТЬ ТАКЖЕ:  Виртуальный номер для приема смс: так ли это выгодно?

Create Access DB (v2): Справочник по C#

0.00 (0%) 0 votes

ОСТАВЬТЕ ОТВЕТ

Пожалуйста, введите ваш комментарий!
пожалуйста, введите ваше имя здесь