Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET2.0 C#2.0 .NET3.0 C#3.0 VS2008 , +
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 7-Jun-13 21:41pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Mohammed Hameed at 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 at 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[^]
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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)[^]
  Permalink  
v2
Comments
Mohammed Hameed at 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 at 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 at 9-Jun-13 15:44pm
   
Okay, thanks. I'll check the links.
Maciej Los at 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 at 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.
Maciej Los at 9-Jun-13 16:08pm
   
In my opinion this is the best approach in this case.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  

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

  Print Answers RSS
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 8 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100