Open the file as a StreamReader, read it line after line. For each line
read, split it ( string[] arrParams = strLine.Split( new char[] {
'\t' } ) ). Then create a SQL Insert statement with parameters and
execute it using SqlCommand object:
1: SqlCommand cmd = new SqlCommand( "insert into table1( field1,
field2 ) values( @field1, @field2 )", connection );
2: cmd.Parameters.Add( new SqlParameter( "@field1", arrParams[0] );
3: cmd.Parameters.Add( new SqlParameter( "@field2", arrParams[1] );
4: cmd.ExecuteNonQuery();
For each next line of text, lines 2 and 3 of the sample will change to:
cmd.Parameters["@field1"].Value = arrParams[0];
cmd.Parameters["@field2"].Value = arrParams[1];
I want to make it user friendily. I want to use window forms and
select
files. Is this possible. But after selecting tab delimeted file what
should
I do.
:
Hi,
You can use either Bulk Insert or DTS to import the data directly
into the
SQL.
If you need to make some adjustment to the data you can always read
the file
into your program and then use ADo.NET to insert the data. This
variant is
slower that the direct ways though.
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Could you please help me in this project. I have aTab delemeted
file. It
has 20 columns and some data. I have to import this data into SQL
Server.
I
am using sql express edition. I am using Window forms to load the
files It
doesn't have import or export wizard. Do you have any idea how can
I do
that.