您的位置:首页 > 其它

写入txt文件

2008-04-01 16:55 113 查看
DateTime datatimes;
datatimes=DateTime.Now;
string filepath=System.Configuration.ConfigurationSettings.AppSettings["ConnenctionStringBaseData"]+SCode+datatimes.ToString("yyyy-MM-dd").Substring(0,4)+datatimes.ToString("yyyy-MM-dd").Substring(5,2)+datatimes.ToString("yyyy-MM-dd").Substring(8,2)+".txt";
StreamWriter sw=new StreamWriter(filepath,false,System.Text.Encoding.Default);
sw.BaseStream.Seek(0, SeekOrigin.End);//设置写数据流的起始位置为文件流的末尾

for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
sw.Write("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\" \"{7}\" \"{8}\" \r\n",
ds.Tables[0].Rows[i][0].ToString(),
ds.Tables[0].Rows[i][1].ToString(),
ds.Tables[0].Rows[i][2].ToString(),
ds.Tables[0].Rows[i][3].ToString(),
ds.Tables[0].Rows[i][4].ToString(),
ds.Tables[0].Rows[i][5].ToString(),
ds.Tables[0].Rows[i][6].ToString(),
ds.Tables[0].Rows[i][7].ToString(),
ds.Tables[0].Rows[i][8].ToString()
);
}
sw.Flush();
sw.Close();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: