private DataTable TxtToDataSet(string Filename)
{
DataSet ds=new DataSet();
DataTable output=new DataTable("student");
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
StreamReader sr = new StreamReader(Filename);
String line;
// Read and display lines from the file until the end of
// the file is reached.
if((line = sr.ReadLine())!=null)
{
string[] strs=line.Split('\t');
foreach(string s in strs)
output.Columns.Add(s);
}
DataRow myRow;
while ((line = sr.ReadLine()) != null)
{
myRow = output.NewRow();
int i=0,j=0,linelength=strs.Length;
foreach(string s in strs)
{
myRow[j++]=s;
if (j==linelength)
{
j=0;
i++;
}
}
output.Rows.Add(myRow);
}
ds.Tables.Add(output);
}
catch (Exception e)
{
// Let the user know what went wrong.
MessageBox.Show("The file could not be read:");
MessageBox.Show(e.Message);
}
//return ds;
return output;
}