Solved

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

Posted on 2007-11-19
2
1,089 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 59
TFS 2015 Access denied. 1 30
ASP.NET data base connection 35 43
Need help for captcha 2 22
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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