DataSet -> Comma/Tab delimited
-
I'm writing a small application that needs to take a DataSet and dump it to either a Comma Delimited text file or a Tab delimited text file. I was wondering if there are any "proper" ways to do this, using built in functions or classes, or if I should just manually write out the proper format to a standard text file. Writing it out myself is trivial, but if theres an established way of doing this with .NET I would like to know. Thanks Dave Ratti
-
I'm writing a small application that needs to take a DataSet and dump it to either a Comma Delimited text file or a Tab delimited text file. I was wondering if there are any "proper" ways to do this, using built in functions or classes, or if I should just manually write out the proper format to a standard text file. Writing it out myself is trivial, but if theres an established way of doing this with .NET I would like to know. Thanks Dave Ratti
Nope, just a "proper" way to write it out to XML.
Reminiscent of my younger years...
10 LOAD "SCISSORS" 20 RUN
-
Nope, just a "proper" way to write it out to XML.
Reminiscent of my younger years...
10 LOAD "SCISSORS" 20 RUN
-
Search for "toub" on GotDotNet.com. He has written a CSV Data"Thingy". Too tired to remember now :zzz: leppie::AllocCPArticle(Generic DFA State Machine for .NET);
-
I'm writing a small application that needs to take a DataSet and dump it to either a Comma Delimited text file or a Tab delimited text file. I was wondering if there are any "proper" ways to do this, using built in functions or classes, or if I should just manually write out the proper format to a standard text file. Writing it out myself is trivial, but if theres an established way of doing this with .NET I would like to know. Thanks Dave Ratti
By now you have probably already solved this problem, but just incase you havent I recently put the following code together to read a file as a dataset and vice versa :
//read CSV format files into a dataset
public static DataSet ReadFileAsDataSet(string filePath, string fileName)
{
OleDbConnection oCon = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filePath + ";" +
"Extended Properties=\"text;HDR=NO;FMT=Delimited\"");OleDbDataAdapter oCmd = new OleDbDataAdapter( "select \* from "+fileName, oCon);
DataSet ds = new DataSet();
oCmd.Fill(ds);
oCon.Close();return ds;
}//write a dataset as a file (currently only supports one table)
//produces files with the following format - "val","val","val","val"
public static void WriteDataSetAsFile(string filepath, string fileName, DataSet ds)
{
if(File.Exists(filepath + "\\" + fileName))
File.Delete(filepath + "\\" + fileName);StreamWriter sw = new StreamWriter(filepath + "\\" + fileName, true);
foreach (DataRow dr in ds.Tables[0].Rows)
{
object[] objRowData = dr.ItemArray;
string strRowData = string.Empty;
foreach(object obj in objRowData)
{
strRowData+= "\"" + obj.ToString() + "\",";
}
strRowData = strRowData.Remove(strRowData.Length - 1, 1);
sw.WriteLine(strRowData);
}
sw.Close();
} -
By now you have probably already solved this problem, but just incase you havent I recently put the following code together to read a file as a dataset and vice versa :
//read CSV format files into a dataset
public static DataSet ReadFileAsDataSet(string filePath, string fileName)
{
OleDbConnection oCon = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filePath + ";" +
"Extended Properties=\"text;HDR=NO;FMT=Delimited\"");OleDbDataAdapter oCmd = new OleDbDataAdapter( "select \* from "+fileName, oCon);
DataSet ds = new DataSet();
oCmd.Fill(ds);
oCon.Close();return ds;
}//write a dataset as a file (currently only supports one table)
//produces files with the following format - "val","val","val","val"
public static void WriteDataSetAsFile(string filepath, string fileName, DataSet ds)
{
if(File.Exists(filepath + "\\" + fileName))
File.Delete(filepath + "\\" + fileName);StreamWriter sw = new StreamWriter(filepath + "\\" + fileName, true);
foreach (DataRow dr in ds.Tables[0].Rows)
{
object[] objRowData = dr.ItemArray;
string strRowData = string.Empty;
foreach(object obj in objRowData)
{
strRowData+= "\"" + obj.ToString() + "\",";
}
strRowData = strRowData.Remove(strRowData.Length - 1, 1);
sw.WriteLine(strRowData);
}
sw.Close();
}