Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,093 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 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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