|
-
Sep 15th, 2005, 10:30 AM
#1
Thread Starter
Addicted Member
Create table from VB [Resolved]
Hi
does anyone know how to create tables and table fields from VB code. i am using ADO.
craeting a patch for my application and need to add to add fields to a table in my db. (Ms Access)
Thanks
Last edited by Paradox; Sep 16th, 2005 at 03:12 AM.
Peny wise pound Foolish
-
Sep 15th, 2005, 10:52 AM
#2
Re: Create table from VB
You simply write a 'CREATE TABLE' command in sql and issue it through your ADO connection exactly the same as you would any other SQL query. I can't be bothered to layout the syntax for CREATE TABLE here so here's a link to W3 schools (an excewllent SQL resource BTW)
http://www.w3schools.com/sql/sql_create.asp
-
Sep 16th, 2005, 12:41 AM
#3
Re: Create table from VB
Paradox,
Look in my signature for Free VB Source Code. Go to Import DBase IV files into an Access 2000 Database. This will give you all the info you need.
-
Sep 16th, 2005, 02:29 AM
#4
Re: Create table from VB
Something like this:
VB Code:
Dim sql As String
sql = "create table [MyTable] "
sql = sql & "([MyField1] TEXT (16), "
sql = sql & "[MyField2] DATE, "
sql = sql & "[MyField3] LONG);"
MyConn.Execute sql ' Create the table
Search VB's help for Create table for more info on creating indexes etc
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Sep 16th, 2005, 02:33 AM
#5
Thread Starter
Addicted Member
Re: Create table from VB
Thanks for all your responses, guess dint phrase myself properly, i want to add a field to an existing table, not to create a new table.
rgds
Last edited by Paradox; Sep 16th, 2005 at 02:36 AM.
Peny wise pound Foolish
-
Sep 16th, 2005, 02:36 AM
#6
Re: Create table from VB
Paradox,
look at the project, it won't make a difference which you want to do.
-
Sep 16th, 2005, 03:02 AM
#7
Re: Create table from VB
You can use Alter Table
VB Code:
sql = "Alter Table [MyTable] ADD COLUMN [MyNewColumn] INTEGER"
MyConn.Execute sql
I'm not 100% sure that's the correct syntax, but it should get you started.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Sep 16th, 2005, 03:11 AM
#8
Thread Starter
Addicted Member
Re: Create table from VB
Thanks guys, figured it out
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|