写个组件吧:
public class Users
{
private string username="";
private string password="";
public string UserName
{
get{return this.username;}
set{this.username=value;}
}
public string Password
{
get{return this.password;}
set{this.password=value;}
}
public string CheckUser()
{
SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings["ConStr"]);
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="select UserName,Password from Users where UserName=@uname";
cmd.Parameters.Add("@uname",SqlDbType.VarChar,10);
cmd.Parameters[0].Value=UserName;
string pass="";
try
{
con.Open();
SqlDataReader reader=cmd.ExecuteReader();
if(reader.Read())
{
pass=reader[1].ToString();
}
else
{
reader.Close();
con.Close();
return UserName+"用户存在!";
}
reader.Close();
con.Close();
}
catch(SqlException er)
{
if(con.State==ConnectionState.Open)
con.Close();
return er.Message;
}
if(pass.Trim()!=Password.Trim())
{
return "对不起!"+UserName+"用户密码不正确!";
}
return "OK";
}
}
[此贴子已经被作者于2006-3-21 10:33:11编辑过]
我也学会一点了