.NET txtReader for Text Files
| Author |
|
| Company |
xPortTools Inc. |
| Source Code Available |
No |
| License Type |
Free to try |
| Submitted On |
April 27, 2010 |
| Updated on |
May 21, 2010 |
| .NET Framework |
2.0, 3.5 |
| Cost |
Free |
Description
.NET txtReader for Text Files is a set of classes, specifically designed to read text files and load the data into ADO.NET DataTable/DataSet from .NET applications. The latest version of the component is implemented as a .NET Managed Provider with read-only capabilities which allow it to treat each text file in a folder as a table with the data and read data from character-delimted or fixed columns text files without the need to use any additional providers. This also results in a familiar look-and-feel and allows for future extension of the component. .NET txtReader uses 100% .NET managed code and is designed to use minimal PC memory to achieve maximum performance.
Syntax Example
//Read data using DataAdapter
using xPortTools.TxtClient;
private void LoadDataFromFile() {
TxtConnection connection = new TxtConnection(@"Data Source=C:\SourceFiles");
//Create TxtCommand to specify from which file to query data.
TxtCommand command = (TxtCommand)connection.CreateCommand();
command.CommandText = "Authors.csv;Titles.csv";
command.CommandType = CommandType.TableDirect; //It is always TableDirect
DataSet result = new DataSet();
//Create TxtDataAdapter to load data into the DataSet
TxtDataAdapter textAdapter = new TxtDataAdapter(command);
//Get data from files
textAdapter.Fill(result);
dataGridView1.DataSource = result.Tables[0];
dataGridView2.DataSource = result.Tables[1];
//Release all opened resources
textAdapter = null;
}
//Read data using DataReader
private void ReadFiles() {
TxtConnection connection = new TxtConnection(@"Data Source=C:\SourceFiles");
connection.Open();
//Create TxtCommand to specify from which text files to query data
TxtCommand command = new TxtCommand("Authors.csv;Titles.csv", connection);
TxtDataReader textReader;
//Create and open TxtDataReader
textReader = (TxtDataReader)command.ExecuteReader(CommandBehavior.CloseConnection);
//Read data from the file
OutputReaderContent(textReader);
System.Diagnostics.Debug.WriteLine("------- End of first result --------");
//Advance to the next text file
if (textReader.NextResult()) {
OutputReaderContent(textReader);
}
//Release all opened resources
textReader.Close();
textReader.Dispose();
textReader = null;
command.Dispose();
command = null;
connection.Dispose();
connection = null;
}
Reviews
Submit a review