从数据表中写入行到文本文件 [英] Write Rows from DataTable to Text File
问题描述
public void GenerateDetailFile()
{
if (!Directory.Exists(AppVars.IntegrationFilesLocation))
{
Directory.CreateDirectory(AppVars.IntegrationFilesLocation);
}
DateTime DateTime = DateTime.Now;
using (StreamWriter sw = File.CreateText(AppVars.IntegrationFilesLocation +
DateTime.ToString(DateFormat) + " Detail.txt"))
{
DataTable table = Database.GetDetailTXTFileData();
foreach (DataRow row in table.Rows)
{
sw.WriteLine(row);
}
}
}
不知道我是什么在这里失踪,但我认为这可能是我不知道如何设置它的列名。
Not sure what I'm missing here but I think it might be the column name which I'm not sure how to set it up.
这是工作的罚款,但,当它写入文本文件,它是写这个:
This is working fine, except, when it writes to the text file, it's writing this:
的System.Data.DataRow结果
的System.Data.DataRow结果
System.Data这。 DataRow的结果
的System.Data.DataRow结果
的System.Data.DataRow结果
的System.Data.DataRow结果
的System.Data.DataRow < BR>
的System.Data.DataRow结果
的System.Data.DataRow结果
的System.Data.DataRow结果
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
谁能给我一个手
推荐答案
是这样的:
sw.WriteLine(row["columnname"].ToString());
会更合适。
would be more appropriate.
这篇关于从数据表中写入行到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!