Types variables création table ACCESS
Bonsoir
Voila une petite question simple pour un dimanche soir :
est-ce que quelqu'un sait où je pourrais trouver les types de variables pour une base ACCESS ?
je souhaite faire un "CREATE TABLE ...."
merci
bonne soirée
KaloOopS
librairie com Adox et Microsoft ActiveX Data Object
bonjour
tu passes par la lib com ADOX (Microsoft ADO Ext 2.8 For DDL and Security) & ADODB(Microsoft ActiveX Data Object 2.8 Library).
Le numero de version depend de la version Access intalle sur ta machine.
Voici un exemple de projet Application WinForm qui cree une bd et lui ajoute une table.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//panneau com ajouter une reference à:
// Microsoft ADO Ext 2.8 For DDL and Security
//(librairie DLL=> Data Definition Language)
using ADOX;
//Microsoft ActiveX Data Object 2.8 Library
using ADODB;
using System.IO;
namespace AdoxCSharp
{
public partial class Form1 : Form
{
//Declare un mdb
private ADOX.Catalog Cat;
private string cheminApp= Directory.GetCurrentDirectory() + "\\" ;
private string nomBase= "maBase.mdb";
public Form1()
{
InitializeComponent();
}
private void btnCreateMDB_Click(object sender, EventArgs e)
{
Cat = new ADOX.Catalog();
Cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + cheminApp + nomBase + ";" +
"Jet OLEDB:Engine Type=5");
Console.WriteLine("Database Created Successfully");
Cat = null;
}
private void btnCreateTable1_Click(object sender, EventArgs e)
{
ADODB.Connection Cn ;
ADOX.Table objTable ;
ADOX.Key objKey ;
Cn = new ADODB.Connection();
Cat =new ADOX.Catalog();
objTable = new ADOX.Table();
//Open the connection
Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + cheminApp + nomBase, string.Empty, string.Empty, 0);
//Open the Catalog
Cat.ActiveConnection = Cn;
//Create the table
objTable.Name = "Test_Table";
//Create and Append a new field to the "Test_Table" Columns Collection
objTable.Columns.Append( "PrimaryKey_Field", ADOX.DataTypeEnum.adInteger,0);
//'Create and Append a new key. Note that we are merely passing
//'the "PimaryKey_Field" column as the source of the primary key. This
//'new Key will be Appended to the Keys Collection of "Test_Table"
objTable.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "PrimaryKey_Field", String.Empty, String.Empty);
//'Append the newly created table to the Tables Collection
Cat.Tables.Append(objTable);
//' clean up objects
objKey = null;
objTable = null;
Cat = null;
Cn.Close();
Cn = null;
}
}
} |
bon code....