ASP.NET实现图书管理系统的步骤详解(2)
2.个人信息页面(内容判断不在内)
protected void tianjia() { //添加用户信息 try { //赋予sql字符串数据 string strsql1 = "update yhxx set xm='"+Tet_xm.Text+"',xb='"+tet_xb.Text+"',qq='"+Tet_qq.Text+"',Email='"+Tet_email.Text+"',dizhi='"+tet_home.Text+"',enjioy='"+Tet_enjoy.Text+"' where zh='"+Application["name"]+"'"; // 创建字符串对象 mycom = new SqlCommand(strsql1, myconn); mycom.ExecuteNonQuery(); //关闭数据库 myconn.Close(); Response.Write("<script>alert('添加成功!!')</script>"); Response.Redirect("denglu.aspx"); } catch (Exception ex) { Response.Write("<script>alert('添加失败!!')</script>"+ex.Message.ToString()); } }
3.登录页面(内容判断不在内)
//普通用户登录,管理员登录雷同 try { string sql = "select * from yhxx where zh='"+Tet_zh.Text+"' and mima='"+Tet_mm.Text+"' and yhlb='"+tet_dz.Text+"'"; //创建命令对象 SqlCommand com = new SqlCommand(sql,myconn); //创建读取对象 SqlDataReader dr = com.ExecuteReader(); //成功弹出提示框 //MessageBox.Show("读取成功!!"); if (dr.Read()) { dr.Close(); myconn.Close(); Application["name1"] = Tet_zh.Text; Response.Redirect("index.aspx"); } else { Response.Write("<script>alert('用户名或密码有误!!')</script>"); } } catch (Exception ex) { Response.Write("<script>alert('登录失败!!')</script>"); }
4.图书检索
try { //打开数据库 myconn.Open(); } catch (Exception ex) { Response.Write("<script>alert('数据库打开失败')</script>"); } try { //创建数据字符串 if (tet_name.Text == "") { Response.Write("<script>alert('名称不能为空!')</script>"); } else { string strsql3 = "select BookID as 图书编号,BookName as 图书名称," + "Booklb as 图书类别,Bookzz as 图书作者,Booklr as 图书内容," + "Bookfm as 图书封面,Bookjg as 图书价格,Bookzt as 图书借阅状态 " + " from Bookxx where BookName='" + tet_name.Text + "'"; mycom = new SqlCommand(strsql3, myconn); //打开数据库 //myconn.Open(); // myread = mycom.ExecuteReader(); GridView1.DataSource = myread; GridView1.DataBind(); GridView1.Visible = true; //关闭数据 myread.Close(); myconn.Close(); } } catch (Exception ex) { Response.Write("<script>alert('查询失败!')</script>" + ex.Message.ToString()); }
内容版权声明:除非注明,否则皆为本站原创文章。