In fact this task can be done through ADOX class,but this isn't a standard class that should be referred by right-clicking your gray folder called "References……" and then choose "Add reference……",and then choose "Microsoft ADO Ext. 2.8 for DDL and
Security",switch to COM and add this tool:
And then code like this:
public static void Main()
{
//Create an access database
ADOX.CatalogClass db = new ADOX.CatalogClass();
string conn = "provider=microsoft.jet.oledb4.0;data source=d:\\mytest.mdb";
db.Create(conn);
//Create DataTable
ADOX.TableClass tb = new TableClass();
tb.Name = "Classes";
tb.ParentCatalog = db;
//Create Columns
ADOX.ColumnClass col = new ColumnClass();
col.Type = DataTypeEnum.adInteger;
col.Properties["AutoIncrement"].Value = true;
tb.Columns.Append(col);
ADOX.ColumnClass col2 = new ColumnClass();
col2.Type = DataTypeEnum.adVarChar;
col2.DefinedSize = 10;
col2.Name = "Name";
tb.Columns.Append(col2);
//Do inserting
using (OleDbCommand cmd = new OleDbCommand("insert into Classes([Name])values(@name)",new OleDbConnection(conn)))
{
cmd.Connection.Open();
cmd.Parameters.AddWithValue("@name", "Jack");
Console.WriteLine("OK");
}
}
Marked as answer by DamonNO1 on May 04, 2012 01:41 AM
DamonNO1
Member
1 Points
3 Posts
how to create DB and Tables with T-SQL in Access?
May 02, 2012 08:49 AM|LINK
how to create DB and Tables with T-SQL in Access?
e.g.
C# ,Access,
If(shool name is not exist)
{
create a DB for shool under D disk;
create tables for classes in the DB
}
Else
create tables for classes in the DB
inert a student into class table
Please help me , thanks in advance!
rio.jones
Member
246 Points
53 Posts
Re: how to create DB and Tables with T-SQL in Access?
May 02, 2012 09:28 AM|LINK
check this link this may give you some idea
http://www.codeproject.com/Articles/35665/Top-10-steps-to-optimize-data-access-in-SQL-Server
http://www.dbforums.com/microsoft-sql-server/959613-running-t-sql-query-against-ms-access-database.html
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: how to create DB and Tables with T-SQL in Access?
May 04, 2012 01:35 AM|LINK
Hello DamonNO1:)
In fact this task can be done through ADOX class,but this isn't a standard class that should be referred by right-clicking your gray folder called "References……" and then choose "Add reference……",and then choose "Microsoft ADO Ext. 2.8 for DDL and Security",switch to COM and add this tool:
And then code like this:
public static void Main() { //Create an access database ADOX.CatalogClass db = new ADOX.CatalogClass(); string conn = "provider=microsoft.jet.oledb4.0;data source=d:\\mytest.mdb"; db.Create(conn); //Create DataTable ADOX.TableClass tb = new TableClass(); tb.Name = "Classes"; tb.ParentCatalog = db; //Create Columns ADOX.ColumnClass col = new ColumnClass(); col.Type = DataTypeEnum.adInteger; col.Properties["AutoIncrement"].Value = true; tb.Columns.Append(col); ADOX.ColumnClass col2 = new ColumnClass(); col2.Type = DataTypeEnum.adVarChar; col2.DefinedSize = 10; col2.Name = "Name"; tb.Columns.Append(col2); //Do inserting using (OleDbCommand cmd = new OleDbCommand("insert into Classes([Name])values(@name)",new OleDbConnection(conn))) { cmd.Connection.Open(); cmd.Parameters.AddWithValue("@name", "Jack"); Console.WriteLine("OK"); } }DamonNO1
Member
1 Points
3 Posts
Re: how to create DB and Tables with T-SQL in Access?
May 04, 2012 01:41 AM|LINK
Thanks very much, that's exactly what i want to get.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: how to create DB and Tables with T-SQL in Access?
May 04, 2012 05:02 AM|LINK
Nothing special,welcome to the forum to chat about the technology……:-)