本帖最后由 张彪 于 2011-12-2 13:56 编辑
---------------------- <a href="http://net.itheima.com/" target="blank">Windows Phone 7手机开发</a>、<a href="http://net.itheima.com/" target="blank">.Net培训</a>、期待与您交流! ----------------------
用户登录源代码:
Console.WriteLine("请输入用户名");
string username = Console.ReadLine();
Console.WriteLine("请输入密码");
string password = Console.ReadLine();
SqlConnection conn=new SqlConnection(@"DATA Source=.\SQLEXPRESS;AttachDBEilename=丨DateDirectory丨\Database1.mdf;Integrated Security=True;User Instance=True;");
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
{
cmd.CommandText = "selecct * from T_Users where='" + username + "'";
//cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
{
if (reader.Read())
{
//用户名存在
string dbpassword = reader.GetString(reader.GetOrdinal("password"));
if (password == dbpassword)
{
Console.WriteLine("登陆成功");
}
else
{
Console.WriteLine("密码错误,登录失败");
}
}
else
{
Console.WriteLine("用户名错误");
}
}
}
}
---------------------- <a href="http://net.itheima.com/" target="blank">Windows Phone 7手机开发</a>、<a href="http://net.itheima.com/" target="blank">.Net培训</a>、期待与您交流! ----------------------
|