C#.ASP里面做用户登陆验证 只要连SQL Server的 20分

来源:百度知道 编辑:UC知道 时间:2024/05/30 20:52:32
请教各位高手!我现在要做个C#.net的用户登陆,只要拿SQL Server连接的,在网站上找到的有1个是拿ACCESS的,我的数据库名"message",表名"Login",有2个字段"user_name"和"password".登陆的用户,如果不成功就在本页显示有错误,成功就跳到Demo.aspx页面!我新建了个login.aspx,加入两个TextBox控件,ID属性分别为“txtUsername”和“txtPassword”,Text属性均为空;还有个Button,ID属性为“btnOk”,Text属性别为“登录”..请高手帮我写下这个的详细代码...谢谢了~~

string strCon = "Server=localhots;uid=SQL帐号;pwd=SQL密码;database=message"
string strSql = "select user_name,password from Login where user_name='"+txtUsername.Text+"' and password='"+txtPassword.Text+"'"
OleDbConnection con = new OleDbConnection(strCon);
OleDbCommand cmd = new OleDbCommand(strSql,con);
con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
{
Response.Write("对");
}
else
{
Response.Write("错");
}
dr.Close();
con.Close();

注意:SQL帐号密码是你自己设置的