首页 新闻 会员 周边 捐助

求教!ASP.NET连接Access数据库,运行提示:标准表达式中数据类型不匹配。

0
[已解决问题] 解决于 2012-05-29 15:00

我用的是VS2010和ACCESS2003,

配置文件中连接字符:

 

<connectionStrings>
    <add name ="conns"  connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\桌面\three\base.mdb"/>
  </connectionStrings>

 

*.ASP文件里拖了两个textbox分别用来输入密码和用户名

再拖了一个button按扭来执行成功登陆

代码如下:

  protected void Button1_Click(object sender, EventArgs e)
        {
            string conn = ConfigurationManager.ConnectionStrings["conns"].ToString();
            OleDbConnection con = new OleDbConnection(conn);
            try
            {
                con.Open();
                if (con.State != ConnectionState.Closed)
                {
                    Response.Write("连接成功");
                    string na = TextBox1.Text.Trim();
                    string d = TextBox2.Text.Trim();

                    OleDbCommand cmd = con.CreateCommand();
                   cmd.CommandText = "select * from tabless where id =" + TextBox1.Text.Trim() + " and name='" + TextBox2.Text.Trim() + "'";
                    OleDbDataReader cmdrdr = cmd.ExecuteReader();
                    //判断是否存在
                    if (cmdrdr.Read())
                    {
                        Response.Write("成功登陆");
                        con.Close();
                        con.Dispose();
                    }

                  
                    else
                    {
                        Response.Write("用户名或者密码错误");
                        con.Close();
                    }


                  
                }
                else
                {
                    Response.Write("连接失败");
                }
            }
            catch (Exception ex)
            {

                Response.Write(ex.Message );
            }

 

PS:数据库中就两个字段,一个是id,一个是name,共一条记录,id为1,name为“张三”

 

运行后数据库连接成功,但是登陆不成功,显示:标准表达式中数据类型不匹配。

小飞鸟儿的主页 小飞鸟儿 | 初学一级 | 园豆:184
提问于:2012-05-29 12:02
< >
分享
最佳答案
0
奖励园豆:5
artwl | 专家六级 |园豆:16736 | 2012-05-29 12:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册