Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


importing CSV to MS SQL table

Posted on 2008-06-17
Medium Priority
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 750 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

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

715 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