By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,871 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,871 IT Pros & Developers. It's quick & easy.

C# coding of create table statement

P: 9
I am doing some development for a company and they have given me all the create table statements in a .sql file. Is there any way that I can use the create table statements or the .sql file itself to add these tables to a database created using visual studio. I would use the graphical table creator, but there are a lot of tables with a lot of columns. Thanks, Kevin
Jan 21 '09 #1
Share this Question
Share on Google+
4 Replies

P: 37
u r having the Insert Query for Create a table in a .SqlFile

Using Stream Reader this can be easily

StreamReader sr = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] StreamReader("SqlFile");
[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] strQuery = sr.ReadLine();
SqlConnection sqlcon = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] SqlConnection(connectionstring);
SqlCommand sqlcmd = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] SqlCommand(strQuery,sqlcon);

[/SIZE]if u unable to create to open the .sql File in Stream Reader[/SIZE]

U may copy the Create statement from Sql File to Notepad File[/SIZE]

and Then try

I hope this will Work
Jan 21 '09 #2

P: 37

public void fnInserttable()
StreamReader sr = new StreamReader("SqlFile");
string strQuery = sr.ReadLine();
SqlConnection sqlcon = new SqlConnection(connectionstring);
SqlCommand sqlcmd = new SqlCommand(strQuery,sqlcon);
catch(Exception ex)


pls try this I hope this will help u


With Regards,
Jan 21 '09 #3

P: 9
I don't understand why this would work if copy and pasting the sql code directly as the command string did not work. If I am mistaken and this does something different let me know.
Jan 21 '09 #4

P: 13,264
Which database? MS SQL, Oracle e.t.c?
What is the structure of the .sql file? Are the create table commands separated by some delimiter?
If there is a command provided by the RDBM that allows you to load an sql file and execute the sql in it then that would be the best way.
Jan 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.