473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Plzz reply urgently

hiii i m having a .cs file which i have included in my project---
using this i want to retrive records from a .txt file (plz reply how
to retrive records from datatable)
this is .cs file------------------->>>>>>>>>
using System;
using System.IO;
using System.Data;

namespace CreateProject
{
public class TextRecordset
{
private string mFilePath;
private char[] mDelimiter;
private bool mWithColumnHeader;
private static DataTable mdtatbText = null;

public TextRecordset()
{
mdtatbText = new DataTable();
}

public void NewTextFile(string filePath,string[] columns, char[]
delimiter, bool withColumnHeader)
{
try
{
mFilePath = filePath;
mDelimiter = delimiter;
mWithColumnHeader = withColumnHeader;
mdtatbText = new DataTable();
foreach(string cols in columns)
{
mdtatbText.Columns.Add(cols);
}
}
catch(Exception ex)
{
throw ex;
}
}
public void Insert(string[] record)
{
if(record.Length == mdtatbText.Columns.Count)
{
mdtatbText.Rows.Add(record);
}
}
public void Save(bool withColumnHeader)
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(mFilePath);
if(withColumnHeader)
{
for(int i = 0 ; i < mdtatbText.Columns.Count ; i++)
{
sw.Write(mdtatbText.Columns[i].ColumnName);
if(i < mdtatbText.Columns.Count - 1)
sw.Write("\t");
}
sw.WriteLine();
}
foreach(DataRow dr in mdtatbText.Rows)
{
for(int i = 0 ; i < mdtatbText.Columns.Count ; i++)
{
sw.Write(dr[i]);
if(i < mdtatbText.Columns.Count - 1)
sw.Write("\t");
}
sw.WriteLine();
}
sw.Close();
}
catch(Exception eX)
{
if(sw != null)
sw.Close();
throw eX;
}
}
public DataTable Open(string filePath, char[] delimiter, bool
withColumnHeader)
{
string strLine = null;
try
{
mFilePath = filePath;
mDelimiter = delimiter;
mWithColumnHeader = withColumnHeader;
StreamReader sr = new StreamReader(mFilePath);
strLine = sr.ReadLine();
string[] columns = strLine.Split(mDelimiter);
if(withColumnHeader)
{
foreach(string col in columns)
{
mdtatbText.Columns.Add(col);
}
strLine = sr.ReadLine();
}
else
{
for(int i = 0; i < columns.Length; i++ )
{
mdtatbText.Columns.Add("Column" + (i + 1));
}
}
while(strLine != null)
{
mdtatbText.Rows.Add(strLine.Split(mDelimiter));
strLine = sr.ReadLine();
}
sr.Close();
return mdtatbText;
}
catch(Exception eX)
{
throw eX;
}
}
public DataColumnCollection Columns
{
get
{
return mdtatbText.Columns;
}
}
public DataRowCollection Rows
{
get
{
return mdtatbText.Rows;
}
}
public int RowCount
{
get
{
return Rows.Count;
}
}

public static DataTable getRecSetTable()
{
return mdtatbText;
}

public void setRecSetTable(DataTable dt)
{
mdtatbText = dt;
}

// public bool equals(TextRecordset tr)
// {
//// foreach(DataColumn dc in this.mdtatbText.Columns)
//// {
//// if(!

this.mdtatbText.Rows[dc.ColumnName].ToString().Equals(tr.mdtatbText.Rows[dc.ColumnName].ToString()))
//// {
//// return false;
//// }
//// }
////
//// return true;
// }
}
}

Aug 12 '07 #1
1 1137
zoya,

Why not just use the text provider for OLE DB and use the classes in the
System.Data.OleDb namespace?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"zoya" <pi************@gmail.comwrote in message
news:11*********************@q4g2000prc.googlegrou ps.com...
hiii i m having a .cs file which i have included in my project---
using this i want to retrive records from a .txt file (plz reply how
to retrive records from datatable)
this is .cs file------------------->>>>>>>>>
using System;
using System.IO;
using System.Data;

namespace CreateProject
{
public class TextRecordset
{
private string mFilePath;
private char[] mDelimiter;
private bool mWithColumnHeader;
private static DataTable mdtatbText = null;

public TextRecordset()
{
mdtatbText = new DataTable();
}

public void NewTextFile(string filePath,string[] columns, char[]
delimiter, bool withColumnHeader)
{
try
{
mFilePath = filePath;
mDelimiter = delimiter;
mWithColumnHeader = withColumnHeader;
mdtatbText = new DataTable();
foreach(string cols in columns)
{
mdtatbText.Columns.Add(cols);
}
}
catch(Exception ex)
{
throw ex;
}
}
public void Insert(string[] record)
{
if(record.Length == mdtatbText.Columns.Count)
{
mdtatbText.Rows.Add(record);
}
}
public void Save(bool withColumnHeader)
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(mFilePath);
if(withColumnHeader)
{
for(int i = 0 ; i < mdtatbText.Columns.Count ; i++)
{
sw.Write(mdtatbText.Columns[i].ColumnName);
if(i < mdtatbText.Columns.Count - 1)
sw.Write("\t");
}
sw.WriteLine();
}
foreach(DataRow dr in mdtatbText.Rows)
{
for(int i = 0 ; i < mdtatbText.Columns.Count ; i++)
{
sw.Write(dr[i]);
if(i < mdtatbText.Columns.Count - 1)
sw.Write("\t");
}
sw.WriteLine();
}
sw.Close();
}
catch(Exception eX)
{
if(sw != null)
sw.Close();
throw eX;
}
}
public DataTable Open(string filePath, char[] delimiter, bool
withColumnHeader)
{
string strLine = null;
try
{
mFilePath = filePath;
mDelimiter = delimiter;
mWithColumnHeader = withColumnHeader;
StreamReader sr = new StreamReader(mFilePath);
strLine = sr.ReadLine();
string[] columns = strLine.Split(mDelimiter);
if(withColumnHeader)
{
foreach(string col in columns)
{
mdtatbText.Columns.Add(col);
}
strLine = sr.ReadLine();
}
else
{
for(int i = 0; i < columns.Length; i++ )
{
mdtatbText.Columns.Add("Column" + (i + 1));
}
}
while(strLine != null)
{
mdtatbText.Rows.Add(strLine.Split(mDelimiter));
strLine = sr.ReadLine();
}
sr.Close();
return mdtatbText;
}
catch(Exception eX)
{
throw eX;
}
}
public DataColumnCollection Columns
{
get
{
return mdtatbText.Columns;
}
}
public DataRowCollection Rows
{
get
{
return mdtatbText.Rows;
}
}
public int RowCount
{
get
{
return Rows.Count;
}
}

public static DataTable getRecSetTable()
{
return mdtatbText;
}

public void setRecSetTable(DataTable dt)
{
mdtatbText = dt;
}

// public bool equals(TextRecordset tr)
// {
//// foreach(DataColumn dc in this.mdtatbText.Columns)
//// {
//// if(!

this.mdtatbText.Rows[dc.ColumnName].ToString().Equals(tr.mdtatbText.Rows[dc.ColumnName].ToString()))
//// {
//// return false;
//// }
//// }
////
//// return true;
// }
}
}
Aug 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: blah | last post by:
Need python Pro at newtopython@googlegroups.com , if u wanna help, plz reply to that address. We are python beginners. need a real good Python Programmer for Help. TIA!! -- * Posted with...
1
by: aj | last post by:
plzz help me to add How a Blank row in a datagrid without using dataset or any other. plzzz help me
40
by: dev_cool | last post by:
hello everybody, i'm a new member of this group, this is my first ever post. i've found a c program that prints prime numbers through an infinite loop. But I really don't understand the code....
5
by: irin07 | last post by:
hello... i just learn how to use php,can anyone help me about how to edit database using php,plzz....i need urgently and i really blank about this. this the database dbhelpdesk table...
4
by: Joonshik Kim | last post by:
I was trying to define 3d array with pointer to pointer. I wrote like following. int ***d; nx = 3; ny = 5; nz = 4; d = (int ***)malloc((int) nx*sizeof(int **)); *d = (int **)malloc((int)...
3
by: wise007 | last post by:
I HAVE A PROBLEM ON THAT..i did success on sending sms to phone and sending sms to system...n i do clear about the sms prefix the problem is i need to know how to do the SMS auto reply/auto...
2
by: zaheer181 | last post by:
Hai everybody, Iam assigned a task of implementing fuzzy c means algorithm in matlab to C language using graphics.h and my question is can we implement the same intensity of graphics in matlab...
1
by: dillipb | last post by:
Please Reply Urgently In the given string '<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/${5}\"></param><param name=\"wmode\"...
3
by: ABOD | last post by:
hi all...plzz..help me to solve this Q. write a multithreading program to multiply ttwo matrices M and N. The two matrices may have differnrt size. M is (r*w) and N is(w*z) The result is a r*z...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.