Домой Access Create New Access Database: Справочник по C#

Create New Access Database: Справочник по C#

388
0


using ADOX; //Requires Microsoft ADO Ext. 2.8 for DDL and Security
using ADODB;

public bool CreateNewAccessDatabase(string fileName)
{
bool result = false;

ADOX.Catalog cat = new ADOX.Catalog();
ADOX.Table table = new ADOX.Table();

//Create the table and it's fields.
table.Name = "Table1";
table.Columns.Append("F1");
table.Columns.Append("F2");
try
{
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fileName + "; Jet OLEDB:Engine Type=5");
cat.Tables.Append(table);
//Now Close the database
ADODB.Connection con = cat.ActiveConnection as ADODB.Connection;
if (con != null)
con.Close();
result = true;
}
catch (Exception ex)
{
result = false;
}
cat = null;
return result;
}

Типы данных для столбцов:

  • Access Text = adVarWChar
  • Access Memo = adLongVarWChar
  • Access Numeric Byte = adUnsignedTinyInt
  • Access Numeric Integer = adSmallInt
  • Access Numeric Long Integer = adInteger
  • Access Numeric Single Precision = adSingle
  • Access Numeric Double Precision = adDouble
  • Access Numeric Replicatie-id = adGuid
  • Access Numeric Decimal = adNumeric
  • Access Date / Time = adDate
  • Access Currency = adCurrency
  • Access AutoNumber = adInteger
  • Access Yes / No = adBoolean
  • Access HyperLink = adLongVarWChar
ЧИТАТЬ ТАКЖЕ:  Чтение данных из базы данных Access: Справочник по C#

Пример указания типа данных в столбце:

table.Columns.Append("PartNumber", ADOX.DataTypeEnum.adVarWChar, 6); // text[6]
table.Columns.Append("AnInteger", ADOX.DataTypeEnum.adInteger); // Integer

Create New Access Database: Справочник по C#

0.00 (0%) 0 votes

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

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