Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Table Creation in VB6.0 ADO

Posted on 1999-07-12
4
Medium Priority
?
6,463 Views
Last Modified: 2013-12-25
How do you CREATE a table using VB6.0 and ADO?  How do create and add the fields?
0
Comment
Question by:Calibus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:Calibus
ID: 1506487
Edited text of question.
0
 
LVL 4

Expert Comment

by:agarwal_rahul
ID: 1506488
You can use MS ADO Ext 2.1 for DDL & Security for creating/modifiying table. There are Tables & Columns collections which can be used to add a new table/column.

Hope this helps
0
 

Author Comment

by:Calibus
ID: 1506489
I'd like to know HOW, as in a ADO code sample.
0
 
LVL 4

Accepted Solution

by:
CraigLazar earned 150 total points
ID: 1506490
Hi there this is what i use in my apps
Dim DB As New ADODB.Connection
Dim Rs As New ADODB.Recordset

    DB.Open "Provider=SQLOLEDB.1;Persist Security Info=False;" _
    & "User ID=" & tmpLogonName & ";Password=" & tmpPassword & ";" _
    & "Initial Catalog=Customers;Data Source=Devserv"
    Rs.Open SqlAdo, DB, adOpenStatic, adLockReadOnly, adCmdText


DB.Execute "CREATE TABLE MyTable (FirstName TEXT, LastName TEXT);"

Creates a new table.

Note   The Microsoft Jet database engine doesn't support the use of CREATE TABLE, or any of the DDL statements, with non-Microsoft Jet database engine databases. Use the DAO Create methods instead.

Syntax

CREATE TABLE table (field1 type [(size)] [NOT NULL] [index1] [, field2 type [(size)] [NOT NULL] [index2] [, ...]] [, CONSTRAINT multifieldindex [, ...]])

The CREATE TABLE statement has these parts:

Part      Description
table      The name of the table to be created.
field1, field2      The name of field or fields to be created in the new table. You must create at least one field.
type      The data type of field in the new table.
size      The field size in characters (Text and Binary fields only).
index1, index2      A CONSTRAINT clause defining a single-field index. See the CONSTRAINT clause topic for more information on how to create this index.
multifieldindex      A CONSTRAINT clause defining a multiple-field index. See the CONSTRAINT clause topic for more information on how to create this index.
Remarks

Use the CREATE TABLE statement to define a new table and its fields and field constraints. If NOT NULL is specified for a field, then new records are required to have valid data in that field.
A CONSTRAINT clause establishes various restrictions on a field, and can be used to establish the primary key. You can also use the CREATE INDEX statement to create a primary key or additional indexes on existing tables.
You can use NOT NULL on a single field, or within a named CONSTRAINT clause that applies to either a single field or to a multiple-field named CONSTRAINT. However, you can apply the NOT NULL restriction only once to a field, or a run-time error occurs.

This works well for me :0)
give it a try

Cheers

Craig
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question