C#+Access做的windows窗体程序,在运行登陆后提示:标准表达式中数据类型不匹配。。
详细信息:
************** 异常文本 **************
System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。
   在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.OleDb.OleDbCommand.ExecuteReader()
   在 学生信息管理系统.Login.btnLogin_Click_1(Object sender, EventArgs e) 位置 E:\学生信息管理系统\学生信息管理系统\Form1.cs:行号 49
   在 System.Windows.Forms.Control.OnClick(EventArgs e)
   在 System.Windows.Forms.Button.OnClick(EventArgs e)
   在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   在 System.Windows.Forms.Control.WndProc(Message& m)
   在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
   在 System.Windows.Forms.Button.WndProc(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** 已加载的程序集 **************
mscorlib
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5448 (Win7SP1GDR.050727-5400)
   基本代码: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
学生信息管理系统
   程序集版本: 1.0.0.0
   Win32 版本: 1.0.0.0
   基本代码: file:///E:/学生信息管理系统/学生信息管理系统/bin/Debug/学生信息管理系统.exe
----------------------------------------
System.Windows.Forms
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5446 (Win7SP1GDR.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5447 (Win7SP1GDR.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
IrisSkin2
   程序集版本: 2006.3.22.45
   Win32 版本: 2006.3.22.45
   基本代码: file:///E:/学生信息管理系统/学生信息管理系统/bin/Debug/IrisSkin2.DLL
----------------------------------------
System.Configuration
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
mscorlib.resources
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5448 (Win7SP1GDR.050727-5400)
   基本代码: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
System.Data
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
   基本代码: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Windows.Forms.resources
   程序集版本: 2.0.0.0
   Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
   基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。例如:  <configuration>
   <system.windows.forms jitDebugging="true" />
</configuration>启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。以上是错误信息,下面是调试显示的错误:

学生信息管理系统.exe!学生信息管理系统.Login.btnLogin_Click_1(object sender = {Text = "登录"}, System.EventArgs e = {X = 32 Y = 13 Button = Left}) 行 49   C#
《外部代码》学生信息管理系统.exe!学生信息管理系统.Program.Main() 行 17 + 0x1d 字节    C#
namespace 学生信息管理系统
{
    public partial class Login : Form
    {
        public Login()
        {  
            InitializeComponent();
            skinEngine1.SkinFile = "SteelBlack.ssk";
        }        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }        private void btnLogin_Click_1(object sender, EventArgs e)
        {
            FrmMain Fm = new FrmMain ();
            string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=StudentSystem.mdb";
            string s2 = "select*from login where admin='"+this.txtusername.Text+"' and passid ='"+this.txtstuPSW.Text+ "'and cent='"+comboBox1 .Text +"'";
           
            if (txtusername.Text == "")
            {
                MessageBox.Show("请输入您的用户名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information );
                return;
            }
            if (txtstuPSW.Text == "")
            {
                MessageBox.Show("请输入密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information );
                return;
            }
            if (comboBox1.Text == "")
            {
                MessageBox.Show("请选择您的身份!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information );
                return;
            }
            OleDbConnection cn = new OleDbConnection(s1);
            cn.Open();
            OleDbCommand cm = new OleDbCommand(s2, cn);
            OleDbDataReader dr = cm.ExecuteReader();    此即为错误        
if (dr.HasRows)
            {
                while (dr.Read())
                {
                    string strusername = dr["admin"].ToString().Trim();
                    string username = this.txtusername.Text;
                    string beizhu = dr["cent"].ToString().Trim();
                    if (username == strusername)
                    {
                        string stuPSW = dr["passid "].ToString().Trim();
                        string psw = this.txtstuPSW.Text;
                        if (stuPSW == psw)
                        {
                            if (beizhu == this.comboBox1.Text)
                            {
                                Fm.UserName = strusername;
                                Fm.PassWord = stuPSW;
                                Fm.GLY = beizhu;
                                Fm.Show();
                                txtusername.Text = "";
                                txtstuPSW.Text = "";
                                comboBox1.Text = "";
                                this.Hide();
                            }
                            
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("对不起,你的密码、用户名或身份错误!\n     请重新输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtusername.Text = "";
                txtstuPSW.Text = "";
                comboBox1.Text = "";
                txtusername.Focus();
                } 
           cn.Close();
        }        private void Login_Load(object sender, EventArgs e)
        {        }
    }
}
program.csusing System;
using System.Collections.Generic;
using System.Windows.Forms;namespace 学生信息管理系统
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Login());        }
    }
}

解决方案 »

  1.   

      string s2 = "select*from login where admin='"+this.txtusername.Text+"' and passid ='"+this.txtstuPSW.Text+ "'and cent='"+comboBox1 .Text +"'";改成  string s2 = "select * from login where admin='"+this.txtusername.Text+"' and passid ='"+this.txtstuPSW.Text+ "'and cent='"+comboBox1 .Text +"'";
      

  2.   

    多谢两位了,但是问题不在那里;改过了还是不行,这是调试中显示的局部变量的信息
    Fm {学生信息管理系统.FrmMain, Text: 学生信息管理系统} 学生信息管理系统.FrmMain
     s1   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=StudentSystem.mdb"  string
     s2   "select * from login where admin='liu' and passid ='123'and cent='管理员'" string
    cn {System.Data.OleDb.OleDbConnection} System.Data.OleDb.OleDbConnection
    cm {System.Data.OleDb.OleDbCommand} System.Data.OleDb.OleDbCommand
      dr null System.Data.OleDb.OleDbDataReader
      

  3.   

    你检查下access数据库中的相关字段是不是文本型的。
      

  4.   


    你私心这写标准点好不好cent是不是数字?
     string s1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\StudentSystem.mdb";
     string s2 = "select * from [login] where [admin]='"+this.txtusername.Text+"' and passid ='"+this.txtstuPSW.Text+ "' and cent="+comboBox1.Text +"";
      

  5.   


    select * from login where admin='liu' and passid ='123'and cent=>select * from login where admin='liu' and passid ='123' and cent注意空格
      

  6.   

    断点把SQL 取出来 就知道问题了可以上数据库里跑一下 
      

  7.   

    这个问题简单,假设数据库表A中某字段CL 是整型类型,
    我们在写SQL select * from A where CL='1'是错误的,一般提示标准表达式中数据类型不匹配。
    或者至少一个参数未指定
    如果SQL修改为 select * from A where CL=1  OK
    ACCESS有某些微小的区别