Solved

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

Posted on 2007-11-19
2
1,084 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now