I would like to use a SQL query on a CSV file using C#. There is something like this for java here. Is there anything like this for c#?
You can read, update, delete CSV records with SQL-like query. You can also execute multiple operations sequentially in managed transactions by passing a procedure or using the interactive shell. In the multiple operations, you can use variables, cursors, temporary tables, and other features.
You can use ODBC to run a query against a CSV File :
// using System.Data.Odbc;
string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};" +
"Dbq=C:;Extensions=csv,txt";
OdbcConnection objCSV = new OdbcConnection(strConn);
objCSV.Open();
OdbcCommand oCmd = new OdbcCommand("select column1,column2 " +
"from THECSVFILE.CSV", objCSV);
OdbcDataReader oDR = oCmd.ExecuteReader();
while (oDR.Read())
{
// Do something
}
You can use the appropriate OLE DB provider to query the text file. You can find the query string here:
Textfile Connection String Samples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With