Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.CSV to SQL CE Table?

Is there any way to quickly import data from a .csv or tab delineated .txt into a SQL Compact Edition 3.5 Table?

I have a large amount of data that is impractical for manual input.

I know I can use the BULK INSERT function if I wanted to import into a Server Based SQL Database, but this method does not work in SQL CE.

I use visual studio 2010 and I have SQL Server Management Studio installed.

Any help will be appreciated!

like image 698
Tony Wu Avatar asked Jun 15 '11 01:06

Tony Wu


People also ask

Can you SQL query a CSV file?

querycsv.py is a Python module and program that allows you to execute SQL code against data contained in one or more comma-separated-value (CSV) files. The output of the SQL query will be displayed on the console by default, but may be saved in a new CSV file.

What is SQL CE database?

Microsoft SQL Server Compact (SQL CE) is a compact relational database produced by Microsoft for applications that run on mobile devices and desktops. It includes both 32-bit and 64-bit native support. SQL CE targets occasionally connected applications, and applications with an embedded database.


2 Answers

You can use my VS Add-in, which generates INSERT statements based on a CSV file: http://sqlcetoolbox.codeplex.com

like image 108
ErikEJ Avatar answered Oct 03 '22 05:10

ErikEJ


Maybe simpler is better. Nothing easier than your own code which can be expanded very easily. You could even have it build the table dynamically if you wanted but probably not necessary.

var stuff = from l in File.ReadLines(filename)
            let x = l.Split(new [] {',', ' '}, StringSplitOptions.RemoveEmptyEntries)
                     .Skip(1)
                     .Select(s => int.Parse(s))
            select new
            {
                Sum = x.Sum(),
                Average = x.Average()
            };

see: Read Csv using LINQ

like image 40
phillip Avatar answered Oct 03 '22 03:10

phillip