日期:2014-05-17  浏览次数:20769 次

C#调用Aceess数据库
C#调用Aceess数据库进行查询时可以查询,但当选中复选框时总是报错“语法错误(操作符丢失)在查询表达式'p_sex性别from Persons where p_name like %宝宝%中;界面及代码如下,各位大神帮忙看看,弄了好久都没弄出来!
其中一段代码:
    private void button1_Click(object sender, EventArgs e)
        {

            if (textBox1.Text.Trim() != "")
            {
                Bind1();
                label6.Text = "您按  查号 查询的结果如下:";
            }
            if (textBox2.Text.Trim() != "")
            {
                Bind2();
                label6.Text = "您按  姓名 查询的结果如下:";
            }
            if (textBox3.Text.Trim() != "")
            {
                Bind3();
                label6.Text = "您按  年龄 查询的结果如下:";
            }
            if (textBox4.Text.Trim() != "")
            {
                Bind4();
                label6.Text = "您按  籍贯 查询的结果如下:";
            }
        }
    private void Bind2()
        {
            if (textBox2.Text.Trim() != "")
            {
                string strPath = Application.StartupPath + "\\CHAN.mdb";
                string ConStr = " Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + strPath;
                using (OleDbConnection Olecon = new OleDbConnection(ConStr))
                    try
                    {
                    &nb