protected void Button1_Click(object sender, EventArgs e)
{
string path = Server.MapPath("~/myinfor.htm");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
if (File.Exists(path))
{
StreamReader sread = new StreamReader(path, System.Text.Encoding.UTF8);
string readfile = sread.ReadToEnd();
sread.Close();
SqlConnection scon = new SqlConnection("Data Source=.;Initial Catalog=Eduask_Power;User ID=sa;Persist Security Info=false");
SqlCommand scom = new SqlCommand("select * from Ep_Student", scon);
SqlDataAdapter sd = new SqlDataAdapter();
sd.SelectCommand = scom;
DataSet ds = new DataSet();
sd.Fill(ds, "students");
//int i; string path1 = Server.MapPath("~/makichen/");
StreamWriter swrite = null;
//string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
//for (i = 0; i <ds.Tables["students"].Rows.Count; i++)
//{
foreach (DataRow i in ds.Tables["students"].Rows)
{ string htmlfilename = "showuser" + i[1] + ".htm";
readfile = readfile.Replace("{@userid}", i[0].ToString());
readfile = readfile.Replace("{@userteach}", i[4].ToString());
readfile = readfile.Replace("{@userprash}", i[5].ToString());
swrite = new StreamWriter(path1 + htmlfilename, false, code);
swrite.Write(readfile);
swrite.Close();
}
//}
}
}
在foreach循环那里怎么循环生成静态页面,请各位高手指教?谢谢大家
{
string path = Server.MapPath("~/myinfor.htm");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
if (File.Exists(path))
{
StreamReader sread = new StreamReader(path, System.Text.Encoding.UTF8);
string readfile = sread.ReadToEnd();
sread.Close();
SqlConnection scon = new SqlConnection("Data Source=.;Initial Catalog=Eduask_Power;User ID=sa;Persist Security Info=false");
SqlCommand scom = new SqlCommand("select * from Ep_Student", scon);
SqlDataAdapter sd = new SqlDataAdapter();
sd.SelectCommand = scom;
DataSet ds = new DataSet();
sd.Fill(ds, "students");
//int i; string path1 = Server.MapPath("~/makichen/");
StreamWriter swrite = null;
//string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
//for (i = 0; i <ds.Tables["students"].Rows.Count; i++)
//{
foreach (DataRow i in ds.Tables["students"].Rows)
{ string htmlfilename = "showuser" + i[1] + ".htm";
readfile = readfile.Replace("{@userid}", i[0].ToString());
readfile = readfile.Replace("{@userteach}", i[4].ToString());
readfile = readfile.Replace("{@userprash}", i[5].ToString());
swrite = new StreamWriter(path1 + htmlfilename, false, code);
swrite.Write(readfile);
swrite.Close();
}
//}
}
}
在foreach循环那里怎么循环生成静态页面,请各位高手指教?谢谢大家
解决方案 »
- 求局域网最快速判断webservice是否可用的方法!
- WPF有没的搞头?
- Assembly.load同一程序集,创建实例该如何写?
- 关于在c#中使用word
- 郁闷拉。如何取Button的name属性和text属性
- C#求记事本保存文件的代码格式
- 怎么实现WinForm客户端访问客户端
- C#调用输出结构体数组的C++的dll
- 问问大家关于如果用.NET开发3层架构系统(Winform)的问题
- vs2013 C# WPF 关于GridViewColumn绑定的问题
- webbrowser 显示完flash之后,能否操作flash,就是发送点击flash的命令
- 又做一回傻事,本以为已经解决: 求助一个关于多线程的问题
这样改下:
foreach (DataRow i in ds.Tables["students"].Rows)
{ string htmlfilename = "showuser" + i[1] + ".htm";
String content= readfile.Replace("{@userid}", i[0].ToString());
content = readfile.Replace("{@userteach}", i[4].ToString());
content = readfile.Replace("{@userprash}", i[5].ToString());
swrite = new StreamWriter(path1 + htmlfilename, false, code);
swrite.Write(readfile);
swrite.Close();
}