在作登陆的时候,用mysql数据库
我用的是:using MySQLDriverCS;
然后我在登陆按钮中作的事件:
代码是:
// 登录按钮单击事件
protected void ButtonLogin_Click(object sender, EventArgs e)
{
string sqlstr = "select * from [t_user] where username='" + txtUserName.Text + "'";
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("192.168.10.108", "db", "root", "123456").AsString);//数据库存连接
MySQLCommand cmd = new MySQLCommand(sqlstr, conn);//创建查询用户名是否存在数据对象
try
{
conn.Open();
Response.Write("ddd");
MySQLDataReader sdr = cmd.ExecuteReaderEx();
if (sdr.Read()) //如果用户名输入正确
{
if (sdr["password"].ToString() == txtPassword.Text)//密码正确
{
conn.Close();
Session["username"] = txtUserName.Text.Trim();//存储用户名
Response.Redirect("main.aspx"); //进入系统
}
else
{
Response.Write("");
}
}
else
{
Response.Write("");
}
}
catch (System.Exception ee)
{
Response.Write("");
}
finally
{
conn.Close();
}
}
==========================================================
可是总是连接不上,读不出数取,不知道为什么,有请高手给看看,多谢!