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
Printable View
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
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 :ehh: 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
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.
Something like this:Search VB's help for Create table for more info on creating indexes etcVB 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
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
Paradox,
look at the project, it won't make a difference which you want to do.
You can use Alter TableI'm not 100% sure that's the correct syntax, but it should get you started.VB Code:
sql = "Alter Table [MyTable] ADD COLUMN [MyNewColumn] INTEGER" MyConn.Execute sql
Thanks guys, figured it out