Import/Export CSV from SQLite from C# code - c#

I am trying to figure out an eazy way to load CSV file into SQLite DB using System.Data.SQLite
I saw commandline way to do that i.e .Import mydata.csv mytable
But I need to do this via C# code. Any Idea?

you can create OleDbConnection to CSV file (just google it, it is very easy) then load rows to DataSet, then put that dataset into Sqlite by SqliteConnection. Few lines of code.

You could use the file helpers library if you want also.And well use the ado.net functionality too.

Related

Importing data from csv file to postgresql table using C# and NPGSQL

I am working in a .net mvc web application with using NPGSQL. In my project, I want to update the records in my postgres database using a .csv file. Maybe someone did it? Can someone send sample code? Someone will tell you how to do it?
So far, I have displayed data on my website using C# and NPGSQL.
If you're looking to insert new rows, you may want to look at the PostgreSQL COPY feature; this is exposed by Npgsql via this API.
Otherwise you can use a .NET CSV parser and construct UPDATE statements which you can execute manually.

How to import data from Excel to C# Service based database?

Im using C# and Service based database and I need to import some data from Excel to my database ..How could I possibly do this?? Please help. Thanks a lot.
You can open the excel file with the Excel database driver and read it like any other data source, however this means you need the driver, which isn't installed by default.
Download
HowTo
However if the sheet only contains data and doesn't need any calculations, you can unzip the XLSX file, and find sheet1.xml (or whatever it's called in your file), open it in your app like any other XML file and import the data.
This is likely to be a much better long term solution, since MS has been trying to kill off the Access database driver for ages.
Also, it's been a while, but I don't believe MS recommends using the MSDE from within a service.
I would recommend you to use OfficeOpenXml.Core.ExcelPackage or EPPlus to read/write excel files. Bellow is some links to reference
https://www.nuget.org/packages/OfficeOpenXml.Core.ExcelPackage/
https://github.com/JanKallman/EPPlus
https://www.c-sharpcorner.com/article/import-and-export-data-using-epplus-core/
https://tedgustaf.com/blog/2012/create-excel-20072010-spreadsheets-with-c-and-epplus/
http://www.talkingdotnet.com/import-export-xlsx-asp-net-core/
https://toidicodedao.com/2015/11/24/series-c-hay-ho-epplus-thu-vien-excel-ba-dao-phan-1/
http://www.zachhunter.com/2015/11/xlsx-template-with-epplus-and-web-api-save-as-xlsx-or-pdf/

How to save a csv file into a database?

I am making a window application in asp.net using C#. I want to browse and import .csv file and save it in the database. Importing part I have done. Now, how am i supposed to save it in the database ? I am new to the language so please help
You can use ADO.NET, you will need to look up Data Adapters and the like.
If your Importing the Spreadsheet into a DataTable or DataSet you can use a Data Adapter to populate a table in the Database using an INSERT command.
Look up http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter.aspx
Hope This Helps.
Once you have a file upload mechanism in place, (for example, using the FileUpload control), just iterate through the lines in the CSV file on the server, parse them into fields using an existing CSV reader (don't try to code your own unless your data is completely trivial, you won't handle all of the edge cases), and just execute a bunch of SQL INSERT statements against your database using your calling convention of choice.

dbf file operations in C# .net

I need to create a dbf file which has the table structure of an existing dbf and insert data to it. Also I need to specify the NAME for it which i usually do in excel by insert->Name.
Which is the best and easy way for it. I have tried using OLEDB already. But I need suggestions for the best option.
Have you tried:
System.IO.File.Copy(sourceFileName, destFileName);
Followed by opening the new file and truncating the data leaving the table structure?

Transferring .txt data into .sdf Using Visual C# to display

I'm using Visual c# express 2008.
I have a huge text file that has data similar to this: "text/text/text/text"
I'm using a delimiter to separate the data.
Now I want to transfer this data to an .sdf file that will be displayed in table format through the windowsformapplication using dataGridView.
I already created an sdf with a table (and columns).
I know how to access the .sdf and display through the dataGridView.
My problem is I have no idea how to transfer the data from the txt to the sdf.
I don't want to do it manually because the txt file contains around 20,000 worth of lines.
Resources: I've recycled code from
http://dotnetperls.com/datagridview-tutorial
Thanks to anyone who can help. :3 Ree
From memory (not tested) SqlBulkCopy works with SDF, so then all you need is an IDataReader. If you search for "fast CsvReader" you should find one on codeproject; this works with any delimiter and should work perfectly with SqlBulkCopy (I've used it this way multiple times, although not with sdf).
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx
http://www.codeproject.com/KB/database/CsvReader.aspx
Also, you could try my new Csv2sqlce utility: http://csv2sqlce.codeplex.com

Categories

Resources