using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{
// Add some text to the file.
//遍历dataSet11,
foreach(System.Data.DataRow row in dataSet11.Tables[0].Rows)
{
//遍历当前行的每一列, 如果不为空则输出字段值,否则输出","
for(int col=0;col<dataSet11.Tables[0].Columns.Count;col++)
{
if(!(row[col] is System.DBNull))
{
sw.Write(row[col].ToString());
}
sw.Write(",");
}
sw.WriteLine("");
}
}
{
// Add some text to the file.
//遍历dataSet11,
foreach(System.Data.DataRow row in dataSet11.Tables[0].Rows)
{
//遍历当前行的每一列, 如果不为空则输出字段值,否则输出","
for(int col=0;col<dataSet11.Tables[0].Columns.Count;col++)
{
if(!(row[col] is System.DBNull))
{
sw.Write(row[col].ToString());
}
sw.Write(",");
}
sw.WriteLine("");
}
}
博客展示了一段代码,使用StreamWriter将数据写入TestFile.txt文件。通过遍历dataSet11中第一个表的每一行和每一列,若列值不为空则将其写入文件,最后添加逗号分隔,每行结束后换行。
1432

被折叠的 条评论
为什么被折叠?



