Database 其他信息:查询表达式“pin=”中出现语法错误(缺少运算符)

Database 其他信息:查询表达式“pin=”中出现语法错误(缺少运算符),database,ms-access,Database,Ms Access,我正在尝试使用VisualStudioWindows窗体将数据库值传递到另一个数据库中。如何访问while循环之外的数据?并保存为字符串并将该值传递到form2。在传递到form2时,我一直遇到此错误:附加信息:语法错误查询表达式“pin=”中缺少运算符 我的form1代码: namespace ATM { public partial class Form1 : Form { String conn_string = "Provider=Microsoft.AC

我正在尝试使用VisualStudioWindows窗体将数据库值传递到另一个数据库中。如何访问while循环之外的数据?并保存为字符串并将该值传递到form2。在传递到form2时,我一直遇到此错误:附加信息:语法错误查询表达式“pin=”中缺少运算符

我的form1代码:

namespace ATM
{
    public partial class Form1 : Form
    {
        String conn_string = "Provider=Microsoft.ACE.OLEDB.12.0;Data     Source=C:\\Users\\Dro\\Desktop\\ATM\\Database11.accdb; Persist Security Info=False;";
        OleDbConnection conn = null;
        public int pinnumber = 3300;
        public string dbpin;
        public string oppin;

        public Form1()
        {
            InitializeComponent();

        }

        private void button13_Click(object sender, EventArgs e)
        {

            runQuery();

            //checks PIN is entered or not 
            if (textBox2.Text.Length == 0)
            {
                textBox2.Text = textBox2.Text + "----";
            }
            else if (dbpin == textBox2.Text)//checks whether pin is correct and then shows the form 2(menu)
            {
                Form2 menu = new Form2();
                menu.Show();
                this.Hide();
            }
            else
            {

                textBox1.Text = "The PIN is Incorrect! Try Again!";


            }
        }



        private void button_click(object sender, EventArgs e)
        {

            if (textBox2.Text == "----")
            {
                textBox2.Clear();
                textBox1.Clear();
            }


            if (textBox2.Text.Length < 4)
            {
                Button button = (Button)sender;
                textBox2.Text = textBox2.Text + button.Text;
                textBox2.PasswordChar = '*';

             }


        }





        private void button12_Click(object sender, EventArgs e)
        {
            textBox2.Clear();

        }
        private void runQuery()
        {

             conn = new OleDbConnection(conn_string);
             MessageBox.Show("successfully connected");
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = conn;
            cmd.CommandText = "SELECT * FROM atmDB where pin="+textBox2.Text;
            conn.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                dbpin = dr["PIN"].ToString();

            }
            MessageBox.Show(dbpin);

        }


    }
}

请删除您的问题以删除所有不相关的代码。我们真的不需要所有这些空事件处理程序。只发布实际适用于您遇到的问题的代码,这样我们就不必筛选所有其他噪音。完成此操作后,搜索参数化查询并去掉SQL连接pin=+textBox2.Text,您的问题就会消失。当SQL比较需要用单引号括起来的静态字符串中的字符串时。所以您想要这个:cmd.CommandText=SELECT*来自atmDB,其中pin='+textBox2.Text+';你需要重新标记这个。这是VB吗?CC++?没有严格访问权限的开发者会为您提供答案。