在c#中按不同条件添加搜索

时间:2015-09-18 19:26:01

标签: c# .net search

我想知道如何在组合框中查看用户是否选择了医生姓名或专科医生,如果用户从组合框中选择医生姓名,则第一个if条件应该运行,但如果用户输入医生特殊,则第二个应该跑。但是,当我输入医生名字时,它不起作用。

   if (comboxBox1.Text = "Doctor name") ; 

                {
                    try
                    {
                        OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\dev\\assignt_soft\\healthline_\\healthline_\\healthline_db.accdb");
                        OleDbCommand com = new OleDbCommand("select * from doctorss where uuname='" + textBox1.Text + "'", con);
                        DataTable dt = new DataTable();
                        con.Open();
                        dt.Load(com.ExecuteReader());
                        dataGridView1.DataSource = dt;
                        con.Close();
                        MessageBox.Show("Displaying doctors with the search criteria doctor name");
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }


                    if (comboxBox1.Text = "Doctor special") ; 

                {
                    try
                    {
                        OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\dev\\assignt_soft\\healthline_\\healthline_\\healthline_db.accdb");
                        OleDbCommand com = new OleDbCommand("select * from doctorss where doctor special='" + textBox1.Text + "'", con);
                        DataTable dt = new DataTable();
                        con.Open();
                        dt.Load(com.ExecuteReader());
                        dataGridView1.DataSource = dt;
                        con.Close();
                        MessageBox.Show("Displaying doctors with the search criteria doctor name");
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

0 个答案:

没有答案