Plzz reply urgently


Z

zoya

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.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);
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;
// }


}
}
 
Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

zoya said:
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.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);
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;
// }


}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top