Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

A Text File, C# 2008 and SQL Server 2005 Express

A Text File, C# 2008 and SQL Server 2005 Express

A Text File, C# 2008 and SQL Server 2005 Express



As you can see from the subject line I am wanting to do the above ... which is import a flat text file into SQL 2005 Express using c# 2008.

I am new to this as we are upgrading from a FOXPRO environment to .net

I have a button on a form which on the click event i have a dialog box that opens and i am able to select a text file, BTW this text file is delimited with a Tab and has around 100,000 records in and in each row there is 130 fields all text with average field lengths of varchar(50). This process will be repeated weekly.

Now i can get the Text file into my SQL DB using Bulk Insert fine.

BUT that is not how it is to be done. NO SIR !!!

I am wanting to just make it so that a form will load and it will load into the SQL nice and easy.

Now i have gone around the net looking for a simple way to import this file..... but its not to be easy....

I know i can use BULK insert or DTS but that is not to be used.... BOTH work fine ... but it needs to run from the click event of the button. I don't want the user to have any access to SQL Server what so ever.

I have succesfully created a connection to the data base.

My DataBase is called TESTDB and the Table name is called TEST_TABLE and i have created the table from the specification given. 130 Text Fields !!! OH !!!!

THE only thing i cannot do is to import the records easily into it..... using code ???

IS there a simple way to do this ?????? Can i connect to the DB and run a stored procedure possibly that i could place the BULK INSERT code in and pass a parameter to the stored procedure stating where to find the file on the server as it will be in different places as each week?

This has been driving me mad for a while ... and i would have thought it would be easy to do as it was in fox alas it is not :(



RE: A Text File, C# 2008 and SQL Server 2005 Express

Get a small sample working.
There are several drastically different approaches to this.

DB Security:
You can connect using a database user account. Then your application can connect with that account.

File Processing:
You can either create a stored procedure, with 130 parameters and call that.
Another option is to add a DBML to your project. This requires at least .Net 3.5
Using LINQ is nicer, and gives you a class to work with.

I advise you NOT do dynamic SQL generation and just run the string. This opens you up to attacks you can't even think of.


You've got questions and source code. We want both!
Oh? That? That's not an important password. - IT Security Admin (pw on whiteboard)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close