数据库:sql 2k
user:sa
psw:sa
表中属性:
user
psw
谁帮我讲解一下语句好吗?
谢谢了
http://www.chinabs.net/aspnet/default.asp?infoid=40
注册:
一个用户表,里面存放那些注册信息.
用户填写那些信息,你还需要使用验证控件,进行一些输入合法性的验证,验证通过后,保存到数据库中.
登陆:
让用户输入用户名和密码
用服务端验证方式
做个asp:Button,写click事件,取得你的用户,密码,构造sql语句验证
错的话出个提示,对的话,转到登录后的页面
//可以用用看
public String Login(string workId,string password)
{
SqlConnection myConnection = new SqlConnection (ConfigurationSettings.AppSettings["ConnectionString"]) ;
SqlCommand myCommand = new SqlCommand ("Aspx_UserLogin",myConnection) ;
myCommand.CommandType = CommandType.StoredProcedure ;
//Add WorkId ;
SqlParameter paramWorkId = new SqlParameter ("@WorkId",SqlDbType.NVarChar,10) ;
paramWorkId.Value = workId ;
myCommand.Parameters.Add(paramWorkId) ;
//Add Password ;
SqlParameter paramPassword = new SqlParameter ("@Password",SqlDbType.NVarChar,10) ;
paramPassword.Value = password ;
myCommand.Parameters.Add(paramPassword) ;
//Add UserId ;
SqlParameter paramUserId = new SqlParameter ("@UserId",SqlDbType.Int,4) ;
paramUserId.Direction = ParameterDirection.Output ;
myCommand.Parameters.Add(paramUserId) ;
//Open the Connection and Execute the Command ;
myConnection.Open() ;
myCommand.ExecuteNonQuery() ;
myConnection.Close() ;
int UserId = (int) (paramUserId.Value) ;
if (UserId == 0)
return null ;
else
return UserId.ToString() ;
}
//==============================
void Page_Load(Object sender,EventArgs e)
{
if(Request.Form["workId"]!= null)
{
Air.UserDB UserSystem = new Air.UserDB() ;
string UserId = UserSystem.Login(Request.Form["workId"],Request.Form["password"]) ;
if (UserId == null)
{
string scriptStr = "<script>alert(用户名或者密码有错误,请重新登陆!)<" ;
scriptStr += "/" ;
scriptStr += "script>" ;
Response.Write(scriptStr) ;
}
else
{
Air.UserDetails userDetails = UserSystem.GetUserDetails(UserId) ;
Response.Redirect("Main.aspx");
}
}
}