资源描述:
《东莞职业技术学院asp考试资料2》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、建数据库BOOK:bookidbooknameauthorpublisherpubdatesummarypriceimageCAT:bookidusernamequantityUSER:usernamepasswordemailquestionanswerrole二、母版与CSS(20分钟)三、注册与登录(1)注册(register)protectedvoidButton1_Click(objectsender,EventArgse){通用部分sqlCmd.CommandText="insertinto[user](username,password,email
2、,question,answer,role)values(@username,@Password,@email,@question,@answer,0)";sqlCmd.Parameters.AddWithValue("@username",TextBox1.Text);sqlCmd.Parameters.AddWithValue("@password",TextBox2.Text);sqlCmd.Parameters.AddWithValue("@email",TextBox4.Text);sqlCmd.Parameters.AddWithValue("@ques
3、tion",TextBox5.Text);sqlCmd.Parameters.AddWithValue("@answer",TextBox6.Text);sqlCmd.Connection=sqlConn;try{sqlConn.Open();sqlCmd.ExecuteNonQuery();Response.Redirect("registerok.aspx");}catch(SqlExceptionex){Response.Redirect("registerfailure.aspx");}finally{sqlConn.Close();}(2)登录(login
4、)protectedvoidButton1_Click(objectsender,EventArgse){SqlConnectionsqlConn=newSqlConnection();sqlConn.ConnectionString="DataSource=.\SQLEXPRESS;"+"AttachDbFileName=
5、DataDirectory
6、Book.mdf;"+"IntegratedSecurity=True;UserInstance=True";SqlCommandsqlCmd=newSqlCommand();sqlCmd.CommandText=
7、"select*from[user]where(username=@uname)and(password=@pword)";sqlCmd.Parameters.AddWithValue("@uname",TextBox1.Text);sqlCmd.Parameters.AddWithValue("@pword",TextBox2.Text);sqlCmd.Connection=sqlConn;try{sqlConn.Open();SqlDataReadersqlDR=sqlCmd.ExecuteReader();if(sqlDR.HasRows){Session["
8、username"]=TextBox1.Text;Response.Redirect("loadok.aspx");}else{Response.Redirect("loadfailure.aspx");}}catch(SqlExceptionex){Response.Redirect("registerfailure.aspx?ex="+ex.Message);}finally{sqlConn.Close();}}一、数据库操作(1)搜索(在主页中page_load事件)publicpartialclassindex:System.Web.UI.Page{prot
9、ectedvoidPage_Load(objectsender,EventArgse){if(IsPostBack==false){GridView1.DataSource=GetDataSource();//设置GridView控件的数据源GridView1.DataBind();//与数据源绑定}}privateDataSetGetDataSource(){SqlConnectionsqlConn=newSqlConnection();//新建数据库连接对象sqlConn.ConnectionString="DataSource=.\SQLEXPRESS;