Help! How to create a database dynamically??

Hi,

There is a listbox in a dialog, which contains the names of some attributes.

after the user chooses some attributes, i want to create a new databse with these names (the values can be obtained from the old database). Anyone knows how to do that? samples are welcomed!

 Pls Help! I need to solve it urgently!
 Thanks a lot!

greenbirdAsked:
Who is Participating?
 
inprasConnect With a Mentor Commented:
Have a tamplate of MS Acces database with no tables in it
When User chooses to create a database copy the template to the user desired name then open it using either ODBC or DAO

then use
CDatabase database;
database.Open(...);

database.ExecuteSQL("CREATE TABLE tablename Col1 Prop1, Col2 Prop2");
in case U use CDatabase

or if U use CDaoDatabase then
CDatabase database;
database.Open(...);

database.ExecuteSQL("CREATE TABLE tablename Col1 Prop1, Col2 Prop2");

These Prop1, Prop2 etc depend on what UR user has selected in ListBox

Hope this helps
inpras
0
 
ZoppoCommented:
just listening ...
0
 
greenbirdAuthor Commented:
Hi, zoppo,

???? what do u mean huh? can not get it leh...

pls help me!
thanks a lot!
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
ZoppoCommented:
sorry, but I can't help you ...

I just added this comment to be notified when comments/answers are posted, because I'm interested too ... it's usual in EE to do this if one does not have to say anything to a question but wants to know what's going on...

ZOPPO
0
 
pagladasuCommented:
What will you be using? DAO or ODBC
0
 
inprasCommented:
What database?
MS Access, Oracle.....?????
0
 
greenbirdAuthor Commented:
Hi,

It is Ms Access. i prefer not to use ODBC. that is i want to create a .mdb database at runtime.

thanks a lot!
0
 
V_BapatCommented:
I am not quite clear what you want.

1. Database can be created dynamically but what kind of database you want to create? Access, ORACLE, Sybase etc.
2. Do you want to use DAO or ODBC? If you have Access, it is preferable to use MFC DAO classes. ODBC otherwise.

Could you describe in detail? This will help us to answer you correctly and fast.

All the best.

Vicky
0
 
V_BapatCommented:
Sorry. I did not refresh before posting comment.
0
 
inprasCommented:
to copy tamplate U can use CopyFile(.....);
0
 
V_BapatCommented:
What you want is already there in MSDN sample DaoTable. You can use most of that for your app. Don't waste you time redoing that.
0
 
greenbirdAuthor Commented:
Hi, all,

thanks so much for ur kind help!

i will try it out as inpras said. if got any problem, i will come back here again :)

Thanks a million for all the help!
0
 
greenbirdAuthor Commented:
Hi,

i did not refresh when i post the comment :)

Bapat, is it? i will check DaoTable soon, see whether they are what i want. thanks a lot!
0
 
greenbirdAuthor Commented:
Hi, all,

does anyone know how to get the name from the edit box? that is, i ask the user to enter a name in an edit box, then how do i get the name?

Thanks a lot!
0
 
V_BapatCommented:
CString strName;
m_edit.GetWindowText(strName);
0
 
greenbirdAuthor Commented:
Hi,

is
database.ExecuteSQL("CREATE TABLE tablename Col1 Prop1, Col2 Prop2");

the syntex correct? it always gives me an error message.

i find in web the SQL command is :

create table table_name (field_type field_name...)
but it also not correct one...

any one know the correct syntex ? or where to look it up in the web?

thanks a  lot!
0
 
ghimirenirajCommented:
create table table_name(a varchar2,
b date,c int,
d date)


but watch out
the data types may be diff with diff
databases

you can't use varchar2 in SQl SERVER
or number

you can't use numeric in oracle


hope this helps


niraj
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.