附加信息:查询表达式中的语法错误(缺少运算符)' pin ='

时间:2015-10-08 22:08:26

标签: database ms-access

我正在尝试使用visual studio窗体将数据库值传递到另一个。如何访问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);

        }


    }
}

0 个答案:

没有答案