How to generate script of a database at run time in c#.
Also knowing what kind of database and driver you are using would be a big help.
Are you talking about generating the DDL that created an object within the database?
For example, I use oracle so I can call the database procedure
object_type IN VARCHAR2,
name IN VARCHAR2,
schema IN VARCHAR2 DEFAULT NULL,
version IN VARCHAR2 DEFAULT 'COMPATIBLE',
model IN VARCHAR2 DEFAULT 'ORACLE',
transform IN VARCHAR2 DEFAULT 'DDL')
by using the select statement
SELECT DBMS_METADATA.GET_DDL('TABLE','SCHEMA','MY_TABLE') FROM DUAL;
You could then use this to output the sql for all your (schema) table objects by doing
SELECT DBMS_METADATA.GET_DDL('TABLE',TABLE_NAME) FROM USER_TABLES;
This is specific for Oracle though and would be different for sql server or mysql.
Build a string with DDL (Data definition language) SQL into a variable named strDDL.
Connect to your DB.
Instantiate SQL command c and set its Connection property.
If you need to know what the exact syntax for the DDL of your specific DBMS is you'll have to consult the documentation of it.
If your database is MS SQLServer then this
] article might help.
You should elaborate you question & be precise. for example Script of existing database, New database on installation etc.
31 Dec '10 - 22:00
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)