问题描述
- 标准表达式中数据类型不匹配
-
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:hospitaldata.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); 提示标准表达式中数据类型不匹配
解决方案
那就去掉单引号
string sql = "select * from [user] where ID ='" + textBox1.Text + "' and 密码 = " + textBox2.Text;
解决方案二:
你的密码是字符串还是数字?
解决方案三:
那就去掉单引号
string sql = "select * from [user] where ID ='" + textBox1.Text + "' and 密码 = " + textBox2.Text";
解决方案四:
id也是数字?那id也要去掉
string sql = "select * from [user] where ID =" + textBox1.Text + " and 密码 = " + textBox2.Text;
时间: 2025-01-19 19:03:29