Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / May 2004



Tip: Looking for answers? Try searching our database.

ADO Programing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gavin - 31 May 2004 19:30 GMT
Hi All,

I can find it anywhere in MSDN Lib about it, but can you add new tables to a
access database using ado code??

Many Thanks,

Gavin.
Veign - 31 May 2004 20:17 GMT
ADO Method:

Use the 'CREATE TABLE' SQL statement..

CREATE TABLE "table_name"
("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
... )

ADOX Method
Sub ADOCreateTable()

  Dim cat As New ADOX.Catalog

  Dim tbl As New ADOX.Table

  ' Open the catalog

  cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

     "Data Source=.\NorthWind.mdb;"

  ' Create a new Table object.

  With tbl

     .Name = "Contacts"

     ' Create fields and append them to the new Table

     ' object. This must be done before appending the

     ' Table object to the Tables collection of the

     ' Catalog.

     .Columns.Append "ContactName", adVarWChar

     .Columns.Append "ContactTitle", adVarWChar

     .Columns.Append "Phone", adVarWChar

     .Columns.Append "Notes", adLongVarWChar

     .Columns("Notes").Attributes = adColNullable

  End With

  ' Add the new table to the database.

  cat.Tables.Append tbl

  Set cat = Nothing

End Sub

Taken from the Migrating from DAO to ADO document:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndao/html/daot
oado.asp


Signature

Chris Hanscom
MVP (Visual Basic)
http://www.veign.com
--

> Hi All,
>
[quoted text clipped - 4 lines]
>
> Gavin.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.