Solved

How to SQL query a tab-delimited text file (ASP.NET 2.0 / C#)?

Posted on 2007-11-19
2
1,087 Views
Last Modified: 2013-11-07
Is there any library or easy way to query a tab-delimited text file from C#? My tab-delimited text file has headers as the first row and was hoping I can use those field names to query the file somehow. Anything like this exists?
0
Comment
Question by:bemara57
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 20312403
You can use ODBC with the Text Driver to read from text files.  You will need a schema.ini to dictate the file structure.

Reference:

Connect to Text Files with the Microsoft Jet ODBC Text Driver
http://users.drew.edu/skass/sql/TextDriver.htm

Bob
0
 
LVL 41

Assisted Solution

by:graye
graye earned 250 total points
ID: 20312832
I presume you're talking about performing an SQL-style query (such as "Select * from Table1 Where Name='Smith'")?   If so, you'd be suprized at what ADO.Net can do without a back-end database.

First of all, you'll need to import the CSV file into a DataTable... TheLearnedOne's posting will do precisely that.
Next, you'll need to figure out what kind of SQL queries you need to do.   For example, if you're just trying to do "filter" with a WHERE clause (as in the example above), then  you can use the DataTable's own Select() method.   Using DataColumnExpressions, you can do a bit more...
But, if you need to do complex SQL select statements (and actually use the SQL language), you'll either have to wait until C# 3.0 to come out or use a 3rd-party "SQL Engine" add on.

Take a look at the following articles (Yeah, they're in VB.Net, but you'll get the point)
http://home.hot.rr.com/graye/Articles/ADO_Expressions.htm
http://home.hot.rr.com/graye/Articles/DataTableJoins.htm
http://home.hot.rr.com/graye/Articles/SQL_Engine.htm
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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