标准表达式中数据类型不匹配。 ?

wojiaoshishi321 2012-06-11 11:51:50
为什么在这个页面就不行 新建了一个页面输入同样的代码就行了呃??
标准表达式中数据类型不匹配。
说明: 执行当前 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)
{

}
}

...全文
145 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdmh 2012-06-11
  • 打赏
  • 举报
回复
把你整个sql语句放出来,看看有没有错误,放到数据库查询中试试看看有没有错,提示是数据类型不符合
另外 'and 这个and前面有没有空格
EnForGrass 2012-06-11
  • 打赏
  • 举报
回复
select * from UserInfor where [UserName]='" + txtName.Text.ToString() + " ' and [pwd]='" + txtPwd.Text.ToString() + "'

注意红色部分
UserName,pwd可能是关键字,and前面确实没有空格

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧