Is it possible to save a csv file to a SQL Server Database table using C#?
Do need to convert the csv file to Binary format in order to do this?
Is there any other way, like saving it in text format(csv is a basically a txt file)?
I'd appreciate it if you could provide some example code.
CSV files are just text. You can create a table that has an nvarchar(max) column and store your CSV files in there.
You have another helpful C# sample for import and export of CSV file with SQL Server. Below is the link:
http://www.codeproject.com/Articles/30705/C-CSV-Import-Export
You can use the data import wizard I believe and point it at a csv file. This should create a table that matches the structure of your imported csv
Related
I have a SQL Server 2008 database from an application which stores office file templates.
The files in the database are stored in hex format (0x504B030414000600...).
With a file signature table (https://www.garykessler.net/library/file_sigs.html), I can find out which file format it is: Microsoft Office Open XML Format Documents (OOXML, like DOCX, PPTX, XLSX ...).
How can I export/convert these hex strings into the original files?
Maybe with C# ...
With the application itself, I can only export 1 file at a time. It would take days to do this with all files (about 1000).
Thank you
Export column with files from SQL Server to single file (it may be very large, but it shouldn't matter). You can for example right click and export results to CSV file.
Write simple C# console application:
use CSV parser to loop over data
inside loop you can make simple if statements to determine document file format
in every iteration convert hex format to blob file and save it somewhere on your drive
I am using sqlite to create a Database with table which has to be just like the csv file along with the headers and data.
what is the best way to create a table in the sqlite database with schema and data from the .csv file.
can i avoid writing the script for the CREATE table?
Thank you in advance!!
I've used SQL Server Import and Export Wizard in the past for creating simple tables from a file. It can automatically detect data types and create the table.
http://technet.microsoft.com/en-us/library/ms141209.aspx
I have already written a script to export data from a single CSV file into SQL Server. I do have to provide the path for that CSV.
I'm trying to figure out how do I modify the code so that it checks a particular folder for CSV files, and then starts processing them one by one. After processing each file, it moves the original file to a different location. Thanks in advance.
Update:
I have a console application written that parses the CSV, connects to SQL database and inserts values. But like I said I have to give the file path. I'm looking for a way to provide only a folder name and the application should look for any CSV files in that folder, parses each file, exports data to SQL, once done moves that file to a different folder and then starts with the next file.
For migrate data from csv try bulk insert
http://msdn.microsoft.com/ru-ru/library/ms188365.aspx
For example
bulk insert [tableName] from 'c:\test.csv'
With (
FIELDTERMINATOR =',',
FIRSTROW=1
)
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?
Can you please suggest how can we export the oracle clob data field to csv file. The table contain other regular data types too. And also if the clob data cannot fit in a csv what are the other options available?
Thanks, Naveen
You can read clob's just like strings. new System.Data.OracleClient.OracleConnection() and so on. When you have the data, you can write CSV's with a StreamWriter because they are just text files.
Storing CLOBs in a CSV file is possible if you use a serious CSV writer that supports:
Multi-line fields
Doubling of double quotes
Setting the encoding
Then you can read the exported file in any other application that has a serious CSV parser, such as Excel.
Just don't go for any CSV classes that have the word simple in their name. They certainly will be too simple.