can any help me how to create a database and its table in the run time of an application.

i need to create new tables also and also specified columns in the table with some record. the application should ask the user to specify the file path also..

help needed plssssss.........

Hi,

What are you using ADO or DAO

Regards
Veena

Why do you want to create a database during run time?

as am learning vb now i need to know how to create database and table during run time

Hi,

Add the following references to your project:
Microsoft AD0 2.8 Library
Microsoft ADO Ext 2.8 DDL and Security

To Create Database:

'
    Dim Cat As New Catalog
    Dim Cn As New ADODB.Connection
    Dim objTable As New ADOX.Table
    ' Create Database
    Cat.Create ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                 "Data Source=C:\MyNewDB.mdb;" & _
                 "Jet OLEDB:Engine Type=4")
    Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyNewDB.mdb"
    Set Cat.ActiveConnection = Cn
    ' Create Tables
    objTable.Name = "EmpMas"
    objTable.Columns.Append "EmpID", adInteger
    objTable.Keys.Append "PrimaryKey", adKeyPrimary, "EmpID"
    '
    objTable.Columns.Append "EmpName", adWChar, 40
    objTable.Columns.Append "JoinDate", adDate
    '
    Cat.Tables.Append objTable
    '
    ' Release objects and Free memory
    Set objTable = Nothing
    Set Cat = Nothing
    Cn.Close
    Set Cn = Nothing
    '
    MsgBox "Created"

REgards
Veena

hmmm... creating a table on runtime? what for?

thanks veena

and i need to know what for is that engine type. if i use that engine type am getting an error while opening the database

Convert/open database

and also the tables are not created in that database.

but if i use the code without the engine type am not getting any error and the database is created perfectly.

can u pls tell me how to save the database in a specified path i.e. it should ask the user the location to store the database..

once again i thank u veena for ur code

keep coding

san

Hi,

You are welcome..
Use a CommonDialog Control to ask the user for File path..
Jet OLEDB:Engine Type=4 (for Lower versions up to Access 97)
if you have Access2K, make it
EngineType =5

Regards
Veena

thanks a lot veena,

i will try the common dialog and get back to you

once again lot of thanks

veena,
i have done the thing with common dialog and its also sucessful. now i have a doubt,

i need to enter the description of the column in a table which we were appending to the database. i.e. open MSAccess database and table in that. in table go to design view. there we will find the description of a particular column.

how to do this one.

Hi,

With the same code as above, to set the decription, use this code:

Dim col As ADOX.Column

Set col = objTable.Columns("EmpID")
col.Properties("Description") = "EmpID Is the PK"

This code has to be written after appending the Column.. (Otherwise you may get error)

Regards
Veena

thats working fine yaar
thanks a lot

Hi,

You are Welcome :)
If you are done, mark this thread as "Solved"

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.