importing CSV to MS SQL table

Posted on 2008-06-17
Last Modified: 2013-11-27

I am using VS 2008 EXPRESS EDITION and MS SQL 2005 Express edition.
Why is text file handling so frustrating in

I have been trying to look up an example of code that would let me import CSV file to MS SQL table.
I want to create a form through which i can enter column names and then by clicking a button i can import respective csv file fields into sql table.

As a beginner i just got lost in the mumbo jumbo of connection strings etc. I could import a csv file in MS SQL using BCP. But how to do it in a vb windows application form by clikin a button in

I tried to look up in books , on net i just cudnt find one complete a beginner its hard to understand incomplete examples.
Question by:rogersam
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5

Expert Comment

ID: 21814024
use SQL management studio express ( and then you can import much easier into SQL express...

LVL 51

Accepted Solution

Mark Wills earned 250 total points
ID: 21814326
Probably for the same reason you are not getting inundated with responses - it gets kinf of open ended, and never ending...

It has been a while since I have needed to write any such code, normally just call a stored procedure in SQL and let it handle it. That might be an option. Pretty sure bcp is considered part of the SQL engine, so would be part of the express version as well (yep, you get the full "engine" in express).

Interesting allowing the column names to be entered - trying to create a mapping of sorts. There in lies part of the challenge. You will have to be able to read the CSV file first and display the columns as "quazzi" names, then allow mapping to "real" names, otherwise how are you going to link it up.

Assume the form is not the issue - if nothing else, it is just a table of two columns - one is populated with the names of the CSV file, the other is where you enter the real names (and destination table as well)...

So, continuing on a theme of not providing the full answer, There is a reasonable code snippet for handling the CSV file itself :
Have you seen : there is an option there to email the author as well...

The biggest difficulty is not all CSV's are created equal, so there are various degrees of success given the variety of combinations available - especially when you consider type casting as well.

There are more examples in C# - have you thought of that ? They can co-exist (with VB.Net), often find the intellectual "tricky" stuff has more examples in c#

Can write you a stored procedure to unpack into a temporary table - maybe the first 10 records, and return the columns, but not so good with the VB.Net these days...


Author Closing Comment

ID: 31468017
Hi thanx for replying. I will try the stored procedure way.
The CSV files i will be dealing with will be pretty well defined. So that should not bew a proble.

I have to use express editions only thats a condition. I wish I cud use C# , but have to use VB only , thats anoother condition. Damn
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

LVL 51

Expert Comment

by:Mark Wills
ID: 21814486
OK, I will keep a watch, my e-mail is on my bio, or post back here...

just found another link on codeproject - that is where I normally go for inspiration - there are a few examples there as well...


Author Comment

ID: 21814589
cant I use BCP?

i COULDNT FIND A WAY TO INSERT bcp CODE IN MY APPLICATION  code. It should work in the express editions.

Author Comment

ID: 21814609
Also I need a relational database, thats one more condition coz i need to manipulate it.
and yea, as a beginner, code snippets make no sense to me atall....may be am missin something
LVL 51

Expert Comment

by:Mark Wills
ID: 21814728
Yep, BCP is fine... Could also use openrowset and other bulk tools...

Author Comment

ID: 21816196
CAN U enlighten me how to use BCP in a code ?!

Author Comment

ID: 22008090
Alright heres the update, I am using (as conditions) VS 2008 express edition and SqlCe 3.5.

Now the toughest thing is, SSMS 2005 doesn't work with SqlCe 3.5. It gets better, SqlCe doesnot support BULK INSERT either.

So I am just importing the schema from a text file, creating a temp table and then importing data into it record by record. Then I modify the table according to the needs.

Lets see how succesful it is, I am not sure about formatting the text file, have to look into that.
LVL 51

Expert Comment

by:Mark Wills
ID: 22008310
SQLCE or SSCE 3.5 ? they both use sdf, if created on mobile, then might be out of date.  Should be able to use (if latest build) on both desktop and mobile device - do you have all the latest downloads ?

SSMS 2005 will not support - might later, but need to load either VS 2008 or SQL2008 - the latter, you just need the management console, and would strongly suggest getting that.

However if your "design/ development" platform is in SQL 2005, then use that space to design in SQL 2005 and then migrate to SSCE 3.5 via

Also have a look at (with connecting to 3.5) :

Now, SQL Server 2008 Management Studio, is meant to be available and fully supports 3.5, but not yet as a seperate download. They have release the SQL 2008 Express with Advanced Services which does include it :


and all the way down the bottom there is a link to 2008 Express with Advanced Services. Alternatively, get the eval version of SQL Server 2008 and just install the client tools... Please note all this is still pre-release...

Also... Check and the links down the bottom...

1. SQL Server Compact 3.5 and Synchronization Services for ADO.Net v1.0 for Windows Desktop:
Installs the files for SQL Server Compact 3.5 and Microsoft Synchronization Services for ADO.Net for Windows Desktop platform

2. SQL Server Compact 3.5 Server Tools:
Installs the Server Tools on the IIS server enabling merge replication and remote data access (RDA) with SQL Server 2005 and later.

3. SQL Server Compact 3.5 Books Online and Samples:
The download contains SQL Server Compact 3.5 Books Online, Online Read Me and Samples. SQL Server Compact 3.5 Books Online do not install with Visual Studio 2008. The Books Online are only available on the Web.

4. Synchronization Services for ADO.Net v1.0 Books Online:
Synchronization Services provides the ability to synchronize data from disparate sources over two-tier, N-tier, and service-based architectures. The Books Online has more information about Synchronization Services. The forum for Synchronization Services provides technical Q&A about using Synchronization Services.



Author Comment

ID: 22011020
Do I have to uninstall MS SQL 2005 EXPRESS EDITION and SSMS 2005 before I download MS SQL 2008 EXPRESS and SSMS 2008?
LVL 51

Expert Comment

by:Mark Wills
ID: 22012855
no. think there is a link in MSDN that discusses it - might be worth doing a search in there...

Author Comment

ID: 22051849

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question