|
需要购买此门答案请加qq2762169544(微信:2762169544)
简述Web服务器向浏览器提供服务的过程。
42、Global.aspx文件在ASP.NET网站中有什么作用?
43、C#数据类型分为哪两大类?请叙述这两类数据的区别?
四、程序填空题 (共2题,每题10分,共20分)
44、后台实现用户注册和登录功能
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ( 1 ) __________ ;
public partial class Login :
System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection Cn;
protected System.Data.SqlClient.SqlCommand Cm;
protected System.Data.SqlClient.SqlDataAdapter Da;
protected System.Data.DataSet Ds;
protected System.Data.SqlClient.SqlDataReader Dr;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null ||
Session["username"] == "")
{
Response.Redirect("Login.aspx"); //如果Session为空,则转到登陆页.
}
}
protected void Regist_Click(object sender, EventArgs e)
{
string str =
ConfigurationSettings.AppSettings["strConnection"];
Cn = new SqlConnection( ( 2 ) __________ );
Cn.Open();
Cm = new SqlCommand(" ( 3 ) __________ userlogin WHERE username='" + nametex.Text +"'", Cn);
Dr = Cm.ExecuteReader();
if ( ( 4 ) __________ ) //如果存在相同用户名
{
Response.Write("<script>alert('用户已被注册');
window.window.location.href='Login.aspx';</script>");
Dr.Close();
}
else
{
Dr.Close();
SqlCommand ( 5 ) __________ = new SqlCommand("INSERT INTO userlogin
(username,password,email,question,answer) VALUES ('" + nametex.Text +"','" + passwtex.Text + "','" + mailtex.Text +"','" + questex.Text + "','" + anstex.Text +"')", Cn);
int i = Cm2.ExecuteNonQuery();
Response.Write("<script>alert('注册成功');window.window.location.href='Login.aspx';</script>");
}
Cn. ( 6 ) __________ ;
}
protected void Login_Click(object sender, EventArgs e)
{
if ( (7) __________ )
{
string str =ConfigurationSettings.AppSettings["strConnection"];
Cn = new SqlConnection(str);
Cn.Open();
Cm = new SqlCommand("SELECT * FROM userlogin WHERE username='" + us.Text + "' AND password ='" + pas.Text + "'", Cn);
Dr = Cm. ( 8 ) __________ ;
if (Dr.Read())//用户名和密码是否正确
{
Session["username"] = ( 9 ) __________ ;
Session["password"] = ( 10 ) __________ ;
Response.Write("<script>alert('登陆成功');window.window.location.href='Login.aspx';</script>");
Dr.Close();
}
else
{
Response.Write("<script>alert('用户名或密码错误!如果还未注册,请先注册!');window.location.href='Login.aspx';</script>");
}
Cn.Close();
}
else
{
Response.Write("<script>alert('请输入用户名和密码!');window.window.location.href='Login.aspx';</script>");
}
}
}
45、根据提示完成以下程序
private void Button1_Click(object sender, System.EventArgs e)
{
//先清空ListBox2中的选项
( 1 ) __________ ;
//将ListBox1中被选中的项添加到ListBox2中
For ( int i=0;i< this.ListBox1.Items.Count;i++)
{
If (ListBox1.Items[i].Selected)
{
(2) __________ .Add ( (3) __________ );
}
}
//将ListBox1中被选中的项删除
For ( int i=0; i<this.ListBox1.Items.Count; i++)
{
if(this.ListBox1.Items[i].Selected)
{
this.ListBox1.Items. (4) __________ ( (5) __________ );
}
}
}
|
|