①Load()方法将查询出来的DataReader加载到调用它的字符串中
②
SqlDataReader sdr = cmd.ExecuteReader(); //返回一个DataReader类型
③用using关联释放资源(sdr释放资源的时候conn也会释放资源)
using (sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))//返回一个DataReader类型 { dt.Load(sdr);//Load()方法将查询出来的DataReader加载到调用它的字符串中 }
④数据库改密码在Web/Web.Config中改
/* 待补充... */
⑤原本Insert语句:insert into category (name) values('ttt')
输入:娱乐新闻')delete category where id=3--
等于:insert into category (name) values('娱乐新闻')delete category where id=3--')
⑥关于删除的时候删除其下的内容的触发器代码编写:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: haonanlyf -- Create date: 2012-7-8 10:37 -- Description: 删除类别触发器 -- ============================================= CREATE TRIGGER trigCategoryDelete ON Category AFTER DELETE AS BEGIN --把刚才删除的记录打印出来 select * from deleted END GO select top 10 n.id,n.title,n.createTime,c.[name] from news n inner join category c on n.caId=c.id order by n.createTime desc exec procNewsSeleteNewNews
⑦
cmd.CommandType = CommandType.StoredProcedure;//将cmd类型改为存储过程
⑧记忆位置(视图、任务列表、注释)
注释前面写成
// TODO:XXX
⑨右键:插入代码段,选择#region,可以讲一个段包含起来,这样缩减到定义查看很清楚
10.删除按钮,客户端提示警告
OnClientClick="return confirm('删除新闻及其评论,确认删除么?')"
11.报错弹窗
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "");
12.隐藏删除按钮
Visible="false"
13.【.cs】页面跳转
Response.Redirect("../newscontent.aspx?newsid=" + id);
14.账号登陆Session
//登陆按钮 protected void btnLogin_Click(object sender, EventArgs e) { //判断验证码是否输入正确 string code = txtCode.Text.Trim().ToUpper(); string rightCode = Session["Code"].ToString(); //Response.Write("输入的验证码是:" + code + ",正确的验证码是:" + rightCode); if (code != rightCode) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", ""); return; } string name = txtName.Text.Trim(); string pwd = txtPassword.Text.Trim(); //把密码转为MD5码的形式 pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5"); bool b = LoginManager.Login(name, pwd); if (b) { //管理员登陆会话从这里开始,知道浏览器关闭才结束 Session["admin"] = name; //跳转语句 Response.Redirect("categorymanager.aspx"); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", ""); } }
15.判断账号是否登陆
protected void Page_Load(object sender, EventArgs e) { //判断Session里面是否存在管理员 if (Session["admin"] != null && Session["admin"].ToString() == "haonanlyf") { //若管理员已登陆 if (!Page.IsPostBack) { //绑定新闻分类到下拉列表 DataTable dt = new CategoryManager().SelectAll(); ddlCategory.DataSource = dt; ddlCategory.DataTextField = "name"; ddlCategory.DataValueField = "id"; ddlCategory.DataBind(); //将需要修改的新闻标题内容显示出来 string id = Request.QueryString["id"]; News n = new NewsManager().SelectById(id); txtTitle.Text = n.Title; ftbContent.Text = n.Content; ddlCategory.SelectedValue = n.CaId; } } else { //未登陆返回登陆窗口 Response.Redirect("login.aspx"); } }