Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import CSV file into SQL Table

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
I want to import a CSV file from a network drive into sql server table using vb.net in a WinForm. I thought this would be easy but have not found a simple solution yet. The CSV file does have field names.

Any pointers?

Thanks in advance.

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
if I was you:

1) Add an XSD to your project, with your SQL connection settings
2) Create a TableAdapter object in your XSD, pointing at the right table
3) Add an Insert Query to your TableAdapter
4)Create a Class in your project that utilises system.io.StreamReader to parse your csv row by row and insert the data (split by ",") with your TableAdapter insert query. As your XSD will be strongly typed, lining your row array (where your split strings will be held) it should be very easy.
5) Make sure you close and dispose everything, especially the StreamReader

John

 
Thanks for responding. I just figured it out two days ago. The file is emailed to me as a CSV and I have to save it. So I am now saving it as an Excel. This process was a lot easier to write.

Thanks.

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top