命名空间要加上
using
System.Text;
using System.IO;
StreamWriter sw = new StreamWriter( " MyTest.txt " , false ,Encoding.Unicode); // 实例化一个写入流,参数分别为 文件保存路径,文件是否覆盖,编码格式
for ( int i = 0 ;i < dataset.Tables[ 0 ].Rows.Count;i ++ )
... {
string userID = dataset.Tables[0].Rows[i]["userID"].ToString().Trim();
string username = dataset.Tables[0].Rows[i]["username"].ToString().Trim();
string logdatetime = dataset.Tables[0].Rows[i]["logdatetime"].ToString().Trim();
string exitdatetime = dataset.Tables[0].Rows[i]["exitdatetime"].ToString().Trim();
string text = "用户编号为"+userID+",用户名为"+username+"登陆时间"+logdatetime+"退出时间"+exitdatetime;
sw.WriteLine(text); //将日志写入日志文件
}
sw.Close();
SaveFileDialog save = new SaveFileDialog();
save.FileName = " MyTest.txt " ; // 保存文件
using System.IO;
StreamWriter sw = new StreamWriter( " MyTest.txt " , false ,Encoding.Unicode); // 实例化一个写入流,参数分别为 文件保存路径,文件是否覆盖,编码格式
for ( int i = 0 ;i < dataset.Tables[ 0 ].Rows.Count;i ++ )
... {
string userID = dataset.Tables[0].Rows[i]["userID"].ToString().Trim();
string username = dataset.Tables[0].Rows[i]["username"].ToString().Trim();
string logdatetime = dataset.Tables[0].Rows[i]["logdatetime"].ToString().Trim();
string exitdatetime = dataset.Tables[0].Rows[i]["exitdatetime"].ToString().Trim();
string text = "用户编号为"+userID+",用户名为"+username+"登陆时间"+logdatetime+"退出时间"+exitdatetime;
sw.WriteLine(text); //将日志写入日志文件
}
sw.Close();
SaveFileDialog save = new SaveFileDialog();
save.FileName = " MyTest.txt " ; // 保存文件