Solved

Weird Problem with SQL CREATE TABLE?

Posted on 2002-07-16
11
189 Views
Last Modified: 2010-05-02
Hello, I am working on a program that basicly creates a database and I am having problems using the SQL CREATE TABLE to make the tables. The database that I am using is Access (DAO 3.6). Here is a piece of code:
 Set DB = engine.CreateDatabase(txtDatabasePath.Text, dbLangGeneral)
 
  DB.Execute "CREATE TABLE keys (test varchar(10) NOT NULL, ver varchar(1) default 'A', answers varchar(60) NOT NULL)TYPE=MyISAM;", dbFailOnError
  DB.Execute "CREATE TABLE answers (sID varchar(2) NOT NULL, pID varchar(3) NOT NULL, comp_ans varchar(60) default NULL, math_ans varchar(60) default NULL, sci_ans varchar(60) default NULL)TYPE=MyISAM;", dbFailOnError

Is there something wrong that I am missing. I thought for sure that you could do this, but maybe I was mistaken. Thanks a lot for the help.
~evlich
0
Comment
Question by:Evlich
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 32

Expert Comment

by:bhess1
ID: 7157738
The 'TYPE=MyISAM' is not an Access command - it is specific to MySQL.  Try removing that first.

Default is also problematic in Access.  As of Access 97, Default is not accepted as a legal command, but this may have changed in Access 2000.

The default NULL statements can be left off - Access will default to NULL for fields.
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7157788
Do you have to use DAO?  It's much easier using ADO and ADOX.  I can even supply an example if you want to get out of the dark ages...I mean away from DAO.
0
 
LVL 1

Author Comment

by:Evlich
ID: 7157946
Well the defaul let me get through those first tow lines, but I have several more line that it is getting trapped on. Can you use tinyint and stuff like that? Here is the new line that the program gets trapped on:
  DB.Execute "CREATE TABLE prog_submissions (tID TINYINT(2) NOT NULL, problem varchar(5) NOT NULL, correct TINYINT(1) NOT NULL, time TIME NOT NULL, er_code tinyint(1));", dbFailOnError
There are still a few lines after that, but I think that this has all the stuff that is used later on. Thanks a lot.
~evlich
P.S. I would appreciate some links to pages for ADO, I have never actually used it, and it might be better for this.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7157974
Her's a module to create a DB:
Public Function gfAB_CreateDB(asDB as string) As Boolean
    Dim adoxCat     As ADOX.Catalog
   
    On Error Resume Next
   
    If Len(Dir(asDB)) > 0 Then Kill asDB
   
    On Error GoTo Syntax_Error
   
    Set adoxCat = New ADOX.Catalog
   
    adoxCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & asDB
   
    Set adoxCat = Nothing
    gfAB_CreateDB = True
   
Exit_Sub:
    Exit Function
   
Syntax_Error:
    gfAB_CreateDB = False
    Resume Exit_Sub

End Function

Here's a function to create a table:
Public Function gfAB_CreateTable(asDB as string) As Boolean
    Dim adoxCat     As New ADOX.Catalog
    Dim adoxTab     As New ADOX.Table
    Dim adoxCol     As ADOX.Column
   
    On Error GoTo Syntax_Error
   
    adoxCat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & asDB
   
    adoxTab.Name = "TableNameHere"
   
    Set adoxCol = New ADOX.Column
    adoxCol.Name = "ColNameHere"
    adoxCol.Type = adVarWChar
    adoxCol.DefinedSize = 2
    adoxCol.Attributes = adColNullable
    adoxTab.Columns.Append adoxCol
   
    adoxCat.Tables.Append adoxTab
   
    Set adoxCol = Nothing
    Set adoxTab = Nothing
    Set adoxCat = Nothing
   
    gfAB_CreateTable = True
   
Exit_Sub:
    Exit Function
   
Syntax_Error:
    gfAB_CreateTable = False
    Resume Exit_Sub

End Function


The above would create a table with one varchar(2) column.

Hope that helps.
Steve

PS  Don't forget to add a reference to the ado ext.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 7158004
Tinyint(2) - I assume that this is a 2 byte integer?

Here are some Access SQL Conversions for you:

4 byte integer, usually INT or INTEGER in most SQL dialects.  Access SQL = INTEGER

2 byte integer, usually smallint in most SQL dialects.  Access SQL = smallint or integer2

1 byte integer, usually tinyint in most SQL dialects.  Access SQL = integer1 or byte



0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7158013
nope it will create a varchar(2)
this will creat an integer column:
    adoxCol.Type = adInteger
0
 
LVL 1

Author Comment

by:Evlich
ID: 7158651
Well, that worked, only one more problem, how do you do a date/Time field.
~evlich
0
 

Expert Comment

by:Amitabh
ID: 7158881
Following is a link for creating database through ADOX and learning other features.

http://www.able-consulting.com/ADOX_Faq.htm#Q2

regards,
A. Pandey
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7159232
I don't know if you are asking me but here's what to use for dates and times:
adoxCol.Type = adDBDate
adoxCol.Type = adDBTime
adoxCol.Type = adDBTimeStamp
0
 
LVL 32

Accepted Solution

by:
bhess1 earned 50 total points
ID: 7159869
For SQL creation, use DATETIME - Alternates are DATE or TIME - all reate an Access DateTime field
0
 
LVL 1

Author Comment

by:Evlich
ID: 7162618
Thanks a lot. I appreciate all the help and suggestions that I was given by everyone. I will take ADO into consideration.
~evlich
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 77
Put text in a picture ASP.NET C# 2 57
Visual Studio 2005 text editor 10 39
VB6 ListBox Question 4 44
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 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