473,473 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# coding of create table statement

9 New Member
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
4 1809
Manikgisl
37 New Member
hi,
u r having the Insert Query for Create a table in a .SqlFile

Using Stream Reader this can be easily

HI.!!!
[SIZE=2]
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);
sqlcon.Open();
SqlCommand sqlcmd = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] SqlCommand(strQuery,sqlcon);
sqlcmd.ExecuteNonQuery();



[/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
Manikgisl
37 New Member
Hi,

public void fnInserttable()
{
try
{
StreamReader sr = new StreamReader("SqlFile");
string strQuery = sr.ReadLine();
SqlConnection sqlcon = new SqlConnection(connectionstring);
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand(strQuery,sqlcon);
sqlcmd.ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}

pls try this I hope this will help u

bye

With Regards,
Mani
Jan 21 '09 #3
kevin21388
9 New Member
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
r035198x
13,262 MVP
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

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

Similar topics

4
by: maricel | last post by:
Could someone confirm which tablespace is being used when running ALTER & CREATE INDEX. Is it the tempspace or the tablespace where the table resides? Many thanks, maricel
6
by: Bruce | last post by:
I want to create a new table based on an existing table, but I don't want the tables to have any enforced relationship. Is this possible without having to do a CREATE TABLE and an INSERT? ...
3
by: Peter Phelps | last post by:
My problem is as follows: I need automatically iterate through a single field in a table and use the values in the field to create an in-statement. Currently, the character limitation in the...
3
by: Rahul B | last post by:
Hi, I have a user UCLDEV1 which is a part of staff and a group(db2schemagrp1) to which i have not given any permissions. The authorizations of that user are shown as db2 =get authorizations...
1
by: noorulahilah | last post by:
How can i create the table through coding in access? And how can i connect with vb. Suppose "db" is database variable. "stu1" is already existing table name. Now i want to create table "stu2"...
10
by: sathynryn | last post by:
hi !....plz help me to run this coding..... create type browse as object(vs varchar 2(700)); create type visite as table of browse; create table inms(us varchar2(25), visdin visite) nested...
3
by: Shawn Beasley | last post by:
Hi List, I am searching franticly for a solution (or the procedure) to setting the coding of a new DB to UTF-8. I can find no setting in the Server Manager, during creation of the DB, to...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
1
by: Constantine AI | last post by:
I am wanting to import CSV files into Access, which isn't a problem at the moment the code i have is as follows: Dim strSQL As String Dim CSVTable As String Dim FilePath As String ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.