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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class 登录界面 : Form
{
OleDbDataAdapter adapter;
DataTable table = new DataTable();
string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\hospital\data.accdb";

        OleDbConnection connection = new OleDbConnection();


    public 登录界面()
    {
        InitializeComponent();
    }
    private void textbox1_TextChanged(object sender, EventArgs e)
    {
    }
    private void textbox2_TextChanged(object sender, EventArgs e)
    {
    }
    private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {

    }
    private void radioButton2_CheckedChanged(object sender, EventArgs e)
    {

    }
    private void radioButton3_CheckedChanged(object sender, EventArgs e)
    {

    }
    private void radioButton4_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text != "" && textBox2.Text != "")
        {
            string sql = "select * from [user]  where ID ='" + textBox1.Text + "' and 密码 = '" + textBox2.Text + "'";
            adapter = new OleDbDataAdapter(sql, str);
            OleDbCommandBuilder buider = new OleDbCommandBuilder(adapter);
            adapter.InsertCommand = buider.GetInsertCommand();
            table.Clear();
            adapter.Fill(table);
            if (table.Rows.Count > 0)
            {
                Form 挂号缴费界面 = new 挂号缴费界面();
                this.Hide();
                挂号缴费界面.Show();
            }
        }


        if (radioButton1.Checked == true)
        {
            this.Hide();
            new 挂号缴费界面().ShowDialog();

        }
        else if (radioButton2.Checked == true)
        {
            this.Hide();
            new 医生诊断界面A().ShowDialog();
        }
        else if (radioButton3.Checked == true)
        {
            this.Hide();
            new 护士病房管理界面A().ShowDialog();
        }
        else if (radioButton4.Checked == true)
        {
            this.Hide();
            new 药房界面A().ShowDialog();
        }
        else
        {
            MessageBox.Show("请输入信息");
        }
    }
    private void button2_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }
    private void 登录界面_Load(object sender, EventArgs e)
    {
     textBox1.Text = textBox2.Text = string.Empty; 
    }

    private void 登录界面_Load_1(object sender, EventArgs e)
    {

    }


}

}

系统运行到 adapter.Fill(table); 提示标准表达式中数据类型不匹配

4个回答

那就去掉单引号

  string sql = "select * from [user]  where ID ='" + textBox1.Text + "' and 密码 = " + textBox2.Text;

你的密码是字符串还是数字?

qq_27602361
qq_27602361 数字
接近 5 年之前 回复

那就去掉单引号

 string sql = "select * from [user]  where ID ='" + textBox1.Text + "' and 密码 = " + textBox2.Text";
qq_27602361
qq_27602361 还是不行啊
接近 5 年之前 回复

id也是数字?那id也要去掉
string sql = "select * from [user] where ID =" + textBox1.Text + " and 密码 = " + textBox2.Text;

qq_27602361
qq_27602361 回复caozhy: 好了 谢谢了 大神好人啊
接近 5 年之前 回复
caozhy
贵阳老马马善福专业维修游泳池堵漏防水工程 回复qq_27602361: 打开你的access,再检查下几个字段的类型,字符串加引号,不是字符串不要引号。
接近 5 年之前 回复
qq_27602361
qq_27602361 就是这样做的 结果还是 adapter.Fill(table);这显示未处理OleDbException(标准表达式中数据类型不匹配。)
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问