Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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!

0
greenbird
Asked:
greenbird
  • 6
  • 4
  • 3
  • +3
1 Solution
 
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
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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:
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
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now