我作的登陆功能部分,但不能实现,牛人们帮我提提意见
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox UserId;
protected System.Web.UI.WebControls.TextBox Pwd;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvUserid;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvPwd;
protected System.Web.UI.WebControls.Button LogButton;
protected System.Data.SqlClient.SqlConnection myConn;
protected System.Data.SqlClient.SqlCommand myCmd1;
protected System.Web.UI.WebControls.Label Msg;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.myConn = new System.Data.SqlClient.SqlConnection();
this.myCmd1 = new System.Data.SqlClient.SqlCommand();
this.LogButton.Click += new System.EventHandler(this.LogButton_Click);
//
// myConn
//
this.myConn.ConnectionString = "data source=f95;initial catalog=user;password=111111;persist security info=True;u" +
"ser id=sa;workstation id=f95;packet size=4096";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LogButton_Click(object sender, System.EventArgs e)
{
string userid,pwd;
userid=Userid.Text;
pwd=Pwd.Text;
string mySel="SELECT count(*) as iCount from user where UserID=""+userid+""";
sqlCommand myCmd1=new sqlCommand(mySel,myConn);
myCmd1.Connection.Open();
sqlDataReader Dr1;
Dr1=myCmd1.ExecuteReader();
Dr1.Read();
string Count=Dr1["iCount"].ToString();
Dr1.Close();
myCmd1.Connection.Close();
string DrPwd,DrRoles;
if(Count!="0")
{
mySel="SELECT * from user where UserID=""+userid+""";
sqlCommand myCmd=new sqlCommand(mySel,myConn);
myCmd.Connection.Open();
sqlDataReader Dr;
Dr=myCmd.ExecuteReader();
Dr.Read();
DrPwd=Dr["Password"].ToString();
Dr.Close();
if(DrPwd==pwd)
{
Session["logid"]=userid;//新建一个Session
Response.Redirect("main.aspx");
}
else
Msg.Text="登录密码错.";
}
else
Msg.Text="没有这个用户.";
}
}
}
}
为什么老是提示要输入东西!!!!
谢谢!!!谁有类似的登陆,借我参考一下,我们可以QQ23568154聊!!
E-mail: zone1984@163.com