objconn.Close(); DataTable dt = new DataTable(); myda.Fill(dt); DataSet myds = new DataSet(); myda.Fill(myds, \); if (dt.Rows.Count >= 1) { DataRow rowview = myds.Tables[\].Rows[0]; u_pwd = rowview[\].ToString(); Response.Write(\请记住您的密码: '+'\ + u_pwd + \); } else { Response.Write(\答案错误!');location.href='searchPsw.aspx'\); } } protected void Button2_Click1(object sender, EventArgs e) { TextBoxAnswer.Focus();//使文本框得到焦点,即将插入点光标移到文本框中 //清空文本框中现有文字 TextBoxAnswer.Text = \; } 10. 添加新闻代码: protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); txtsort.Visible = false; } protected void Button1_Click(object sender, EventArgs e) { NewsModeln d = new NewsModeln(); if (DropDownList1.Visible) { d._n_title = TextBox1.Text; d._n_details = TextBox2.Text; d._n_sorts = DropDownList1.Text; d._n_data = Label1.Text; d._n_pictuie = FileUpload1.FileName; d._n_state = Convert.ToString(1); d._n_uname = Session[\].ToString(); } else { d._n_title = TextBox1.Text; d._n_details = TextBox2.Text; d._n_sorts = txtsort.Text; d._n_data = Label1.Text; d._n_pictuie = FileUpload1.FileName; d._n_state = Convert.ToString(1); d._n_uname = Session[\].ToString(); } NewsDAL w = new NewsDAL(); if (w.newadd(d)) { Response.Write(\成功添加');location.href='Default.aspx'\); 第29页
} else { Response.Write(\错误,请重新输入');\); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = \; TextBox2.Text = \; TextBox1.Focus(); } protected void Button3_Click(object sender, EventArgs e) { txtsort.Visible = true; DropDownList1.Visible = false; Button3.Visible = false; } 11. 修改新闻列表代码: protected void Page_Load(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString[\]); } 12. 审核新闻代码: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Convert.ToInt32(Request.QueryString[\]); string str = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[\].ToString(); SqlConnection conn = new SqlConnection(str); conn.Open(); SqlCommand mycmd = new SqlCommand(\ + id, conn); SqlDataReader dr = mycmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr[\].ToString() + \; TextBox2.Text = dr[\].ToString(); TextBox3.Text = dr[\].ToString(); Label1.Text = dr[\].ToString(); TextBox5.Text = Convert.ToString(id); TextBox6.Text = dr[\].ToString(); } conn.Close(); } } protected void Button1_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString[\]); NewsDAL w = new NewsDAL(); if (w.newstate(id)) { Response.Write(\审核通过');location.href='newshen.aspx'\); Response.Redirect(\); } else 第30页
{ Response.Write(\审核不通过');\); } } protected void Button2_Click1(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString[\]); NewsDAL d = new NewsDAL(); if (d.newstatedelect(id)) { Response.Write(\已删除');\); Response.Redirect(\); } } 13. 审核新闻列表代码: protected void Page_Load(object sender, EventArgs e) { NewsDAL s = new NewsDAL(); DataTable d = s.getstate(); GridView1.DataSource = d; GridView1.DataBind(); } 14. 修改新闻代码: protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { int id = Convert.ToInt32(Request.QueryString[\]); string str = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[\].ToString(); SqlConnection conn = new SqlConnection(str); conn.Open(); SqlCommand mycmd = new SqlCommand(\+id,conn); SqlDataReader dr = mycmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr[\].ToString() + \; TextBox2.Text =dr[\].ToString(); TextBox3.Text = Convert.ToString(id); TextBox4.Text = dr[\].ToString(); } conn.Close(); } } protected void Button1_Click(object sender, EventArgs e) { NewsModeln d = new NewsModeln(); d._n_title = TextBox1.Text; d._n_details = TextBox2.Text; d._n_id = Convert.ToInt32(TextBox3.Text); d._n_sorts = TextBox4.Text; NewsDAL s = new NewsDAL(); if (s.newupdata(d)) { Response.Write(\更新成功');location.href='newedit.aspx'\); //Response.Redirect(\第31页
} else { Response.Write(\更新失败');\); } } protected void Button2_Click(object sender, EventArgs e) { Response.Redirect(\); } 15. 管理用户信息: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Convert.ToInt32(Request.QueryString[\]); string str = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[\].ToString(); SqlConnection conn = new SqlConnection(str); conn.Open(); SqlCommand mycmd = new SqlCommand(\ + id, conn); SqlDataReader dr = mycmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr[\].ToString() + \; TextBox2.Text = dr[\].ToString(); TextBox3.Text = dr[\].ToString(); TextBox4.Text = dr[\].ToString(); TextBox6.Text = dr[\].ToString(); TextBox7.Text = dr[\].ToString(); TextBox8.Text = dr[\].ToString(); TextBox9.Text = dr[\].ToString(); TextBox10.Text = Convert.ToString(id); } conn.Close(); } } protected void Button1_Click(object sender, EventArgs e) { NewsModelu u = new NewsModelu(); u._u_name = TextBox1.Text; u._u_pwd = TextBox2.Text; u._u_gender = TextBox3.Text; u._u_birthday = TextBox4.Text; u._u_qtn = TextBox6.Text; u._u_answer = TextBox7.Text; u._u_score = TextBox8.Text; u._u_lim = TextBox9.Text; u._u_id = Convert.ToInt32(TextBox10.Text); NewsDAL us = new NewsDAL(); if (us.userupdata(u)) { Response.Write(\修改成功');location.href='users.aspx'\); } else { Response.Write(\修改失败');\); 第32页
} } protected void Button2_Click(object sender, EventArgs e) { Response.Redirect(\); } 16. 评论管理信息: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Convert.ToInt32(Request.QueryString[\]); string str =System.Web.Configuration.WebConfigurationManager.ConnectionStrings[\].ToString(); SqlConnection conn = new SqlConnection(str); conn.Open(); SqlCommand mycmd = new SqlCommand(\contents.u_name,contents.c_content,contents.c_time,news.n_title from contents left join news on contents.n_id=news.n_id where contents.c_id=\ + id, conn); SqlDataReader dr = mycmd.ExecuteReader(); while (dr.Read()) { txtname.Text = dr[\].ToString() + \; txtcontent.Text = dr[\].ToString(); Label1.Text = dr[\].ToString(); txttitle.Text = dr[\].ToString(); } conn.Close(); } } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect(\); } protected void Button2_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString[\]); NewsDAL d = new NewsDAL(); if (d.connentdelete(id)) { Response.Write(\删除成功');location.href='Comments.aspx'\); } else { Response.Write(\删除失败');\); } } 总结 为做出该新闻系统程序,访问了大量Web网络开发方面的网站,搜集了大量关于Web网络开发的中英文资料,也查阅了大量书籍的源代码作为参考和运用,从中学会了许多ASP.NET和ADO.NET技术关于Web开发方面的知识。 该系统虽然能正常运行,但有的功能还不是太完善,甚至有些功能很不符合逻辑。第33页