Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-19
2
Medium Priority
?
1,101 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 1000 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 1000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

877 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