账户登录模块出现账户类型不匹配?

wojiaoshishi321 2012-06-10 11:53:00
使用双数据库登录 ACCESS 用Radiobutton控制 一个是管理员 一个是用户 管理员是radiobutton1 用户是radiobutton2
管理员那个能正常登录 用户的点击登录就出现错误怎么办呀
错误那行用红色标记了
模块显示类似这种
------------------
|○管理员 ○客户 |
| |
| |
|账户:□□□□□□ |
| |
|密码:□□□□□□ |
| 登录 注册 |
------------------

using System;
using System.Data;
using System.Configuration;
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.Collections;
using System.Data.OleDb;



public partial class _Default : System.Web.UI.Page
{



protected void Button1_Click(object sender, EventArgs e)
{




{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"].ToString();

OleDbConnection myConnection = new OleDbConnection(strConn);

myConnection.Open();


OleDbCommand myCommand = new OleDbCommand("select * from UserInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection);

OleDbDataReader oddr = myCommand.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("Login.aspx");
}



if ((txtName.Text == "") || (txtPwd.Text == ""))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名和密码不能为空!')", true);
return;
}

else
{
oddr.Close();
myConnection.Close();

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名或密码错误!')", true);

txtName.Text = "";
txtPwd.Text = "";
}
}
}


{
string strConn2 = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"].ToString();

OleDbConnection myConnection2 = new OleDbConnection(strConn2);

myConnection2.Open();


OleDbCommand myCommand2 = new OleDbCommand("select * from ClientInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection2);

OleDbDataReader oddr2 = myCommand2.ExecuteReader();


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("Login2.aspx");
}



if ((txtName.Text == "") || (txtPwd.Text == ""))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名和密码不能为空!')", true);
return;
}

else
{
oddr2.Close();
myConnection2.Close();

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('用户名或密码错误!')", true);

txtName.Text = "";
txtPwd.Text = "";
}

}
}

}





标准表达式中数据类型不匹配。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。

源错误:


行 89: OleDbCommand myCommand2 = new OleDbCommand("select * from ClientInfor where UserName='" + txtName.Text.ToString() + " 'and pwd='" + txtPwd.Text.ToString() + "'", myConnection2);
行 90:
行 91: OleDbDataReader oddr2 = myCommand2.ExecuteReader();
行 92:
行 93:




...全文
249 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhujiawei7 2012-06-10
  • 打赏
  • 举报
回复
可能是你插入的数据于数据库字段的数据类型不匹配造成的,请仔细检查数据类型
thought777 2012-06-10
  • 打赏
  • 举报
回复
看看ClientInfor 表中的字段类型是否正确

62,268

社区成员

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

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

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

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