Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I'm creating a tool in Wpf using C#.

Can anybody suggest a best approach to create a table dynamically using C#.

If you have any queries do let me know.


Thanks.
Posted

There is no best approach. Do you have a list of requirements?

You can possibly provide a textbox where the user can type the name of the column.
A dropdown for the type i.e. varchar etc.

Then on click of a button, you can create table based on whatever the user has selected.
 
Share this answer
 
Comments
Mohammed Hameed 8-Jun-13 2:54am    
Hi Abhinav,
I didn't mean approach in that sense. Anyhow let me expalin you further.
Assume that I have the 'Create table' script ready, Now I want to run this script through C# code to create table dynamically instead of manual. The server can be a Sql server or Oracle, it should support both servers.
Hope it is clear now. Thanks.
Abhinav S 8-Jun-13 2:57am    
The data access block in the Enterprise Library can help you build programs to support multiple databases. Note that you still need to handle database level coding (for respective databases) on your own. If you are going to build a big application, you can consider this library. Link[^]
Mohammed Hameed wrote:
Assume that I have the 'Create table' script ready, Now I want to run this script through C# code to create table dynamically instead of manual. The server can be a Sql server or Oracle, it should support both servers.


I'm not sure what you mean writing above words, especially 'Create table' script. If script means procedure/function in C# code, i would suggest you to read about overloading methods and signatures.

3.6 Signatures and overloading[^]
7.4.2 Overload resolution[^]
Method overloading (C# tutorials)[^]
C# Overload (dotnetperls)[^]
 
Share this answer
 
v2
Comments
Mohammed Hameed 8-Jun-13 6:20am    
It will be a string like "CREATE TABLE <TableName>..." containing the query. I should be able to execute this query with a single routine and not depending on a particular db. Basically I dont want to use the SqlConnection or OracleConnection class. I mean, this should support multiple databases. But sorry again, if it makes sense or not I dont know much but I dont want to use any ORM like NHibernate or Entity Framework.
Thanks.
Maciej Los 9-Jun-13 15:38pm    
You can pass 2 parameters: 1. string to create table and 2. connection object ;) Do you know what i mean, now?
Please, refer above links.
Mohammed Hameed 9-Jun-13 15:44pm    
Okay, thanks. I'll check the links.
Maciej Los 9-Jun-13 15:48pm    
Example:
int CreateTable(string sCommand, SqlConnection sqlconn)
int CreateTable(string sCommand, OracleConnection oraconn)

This is only an idea.
Mohammed Hameed 9-Jun-13 15:54pm    
Okay thanks. What you have provided is obviously most of us do it that way, but what I'm asking is for a best approach.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900