关于用户名登陆的问题?在线等。
string username = Request.Form["username"].ToString();
string userpsd = Request.Form["userpsd"].ToString();
// Response.Write("登录的用户名为" + username + "用户密码" + userpsd);
string strCon1 = "Data Source =" + Server.MapPath("wjx.accdb");
string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=false;" + strCon1;
// OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM azhou ", strCon);
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from AdminUser where 用户名='" + username + "' and 密码='" + userpsd + "'", strCon);
请问接下来我该怎么写。。头大
------解决方案--------------------
OleDbConnection cn = new OleDbConnection(strCon );
cn.Open();
String sql = "select * from AdminUser where 用户名=@name and 密码=@pwd";
OleDbCommand cmd = new OleDbCommand(sql, cn);
cmd.Parameters.AddWithValue("@name", username );
cmd.Parameters.AddWithValue("@pwd", userpsd );
OleDbDataReader dr = cmd.ExecuteReader();
if(!dr.HasRows)
{
//用户不存在
}