这个是登陆时验证的代码,我是用Microsoft Visual 2003编写的代码,编译时没有提示错误,浏览的时候才提示错误,以下是代码
=======================================
private void Button1_Click(object sender, System.EventArgs e)
{
if (username.Text == "" || password.Text =="")
{
Label1.Text ="信息填写不完整!";
}
else
{
string sql;
OleDbCommand command;
OleDbDataReader read;
OleDbConnection conn = book.connection();
sql="select * from userlist where username="+book.sqlEncode(username.Text)+" and password="+book.sqlEncode(password.Text);
command=new OleDbCommand(sql,conn);
read=command.ExecuteReader();
if(read.Read())
{
Session["username"]=username.Text;
Response.Redirect ("Login.htm");
}
else
{
read.Close();
Label1.Text = "登陆错误,请重新登陆!";
}
conn.Close();
}
}
}
=======================================
错误:
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。源错误:
行 67: sql="select * from userlist where username="+book.sqlEncode(username.Text)+" and password="+book.sqlEncode(password.Text);
行 68: command=new OleDbCommand(sql,conn);
行 69: read=command.ExecuteReader();
行 70: if(read.Read())
行 71: {
=======================================
private void Button1_Click(object sender, System.EventArgs e)
{
if (username.Text == "" || password.Text =="")
{
Label1.Text ="信息填写不完整!";
}
else
{
string sql;
OleDbCommand command;
OleDbDataReader read;
OleDbConnection conn = book.connection();
sql="select * from userlist where username="+book.sqlEncode(username.Text)+" and password="+book.sqlEncode(password.Text);
command=new OleDbCommand(sql,conn);
read=command.ExecuteReader();
if(read.Read())
{
Session["username"]=username.Text;
Response.Redirect ("Login.htm");
}
else
{
read.Close();
Label1.Text = "登陆错误,请重新登陆!";
}
conn.Close();
}
}
}
=======================================
错误:
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。源错误:
行 67: sql="select * from userlist where username="+book.sqlEncode(username.Text)+" and password="+book.sqlEncode(password.Text);
行 68: command=new OleDbCommand(sql,conn);
行 69: read=command.ExecuteReader();
行 70: if(read.Read())
行 71: {
检查一下book.sqlEncode(password.Text)是什么
我是通过private function book = new function();调用function.cs这个文件里面的sqlEncode而已