标准表达式中数据类型不匹配。 ?
为什么在这个页面就不行 新建了一个页面输入同样的代码就行了呃??标准表达式中数据类型不匹配。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。
源错误:
行 42: OleDbCommand myCommand2 = new OleDbCommand("select * from ClientInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection2);
行 43:
行 44: OleDbDataReader oddr2 = myCommand2.ExecuteReader();
行 45:
行 46: if (RadioButton1.Checked)
源文件: d:\我的文档\Visual Studio 2005\WebSites\2009050946\Default.aspx.cs 行: 44
堆栈跟踪:
[OleDbException (0x80040e07): 标准表达式中数据类型不匹配。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +44
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +155
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +190
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +162
System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +96
System.Data.OleDb.OleDbCommand.ExecuteReader() +6
_Default.btnOK_Click(Object sender, EventArgs e) in d:\我的文档\Visual Studio 2005\WebSites\2009050946\Default.aspx.cs:44
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +78
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +100
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2863
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void btnOK_Click(object sender, EventArgs e)
{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"].ToString();
OleDbConnection myConnection = new OleDbConnection(strConn);
myConnection.Open();
string strConn2 = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"].ToString();
OleDbConnection myConnection2 = new OleDbConnection(strConn2);
myConnection2.Open();
OleDbCommand myCommand = new OleDbCommand("select * from UserInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection);
OleDbDataReader oddr = myCommand.ExecuteReader();
OleDbCommand myCommand2 = new OleDbCommand("select * from ClientInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection2);
OleDbDataReader oddr2 = myCommand2.ExecuteReader();
if (RadioButton1.Checked)
{
if (oddr.HasRows)
{
oddr.Close();
myConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('登录成功!')", true);
//HttpCookie cookies = new HttpCookie("MyCookie");
//cookies["name"] = txtName.Text.ToString();
//cookies.Expires = DateTime.Now.AddMinutes(20);
//Response.Cookies.Add(cookies);
Session["UserName"] = txtName.Text.ToString();
Response.Redirect("Loged.aspx");
}
else
{
oddr.Close();
myConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名或密码错误!')", true);
txtName.Text = "";
txtPwd.Text = "";
}
}
if (RadioButton2.Checked)
{
if (oddr2.HasRows)
{
oddr2.Close();
myConnection2.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('登录成功!')", true);
//HttpCookie cookies = new HttpCookie("MyCookie");
//cookies["name"] = txtName.Text.ToString();
//cookies.Expires = DateTime.Now.AddMinutes(20);
//Response.Cookies.Add(cookies);
Session["UserName"] = txtName.Text.ToString();
Response.Redirect("Loged.aspx");
}
else
{
oddr.Close();
myConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名或密码错误!')", true);
txtName.Text = "";
txtPwd.Text = "";
}
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
}
}
--------------------编程问答-------------------- 把你整个sql语句放出来,看看有没有错误,放到数据库查询中试试看看有没有错,提示是数据类型不符合
另外 'and 这个and前面有没有空格 --------------------编程问答-------------------- select * from UserInfor where [UserName]='" + txtName.Text.ToString() + " ' and [pwd]='" + txtPwd.Text.ToString() + "'
注意红色部分
UserName,pwd可能是关键字,and前面确实没有空格
补充:.NET技术 , ASP.NET