求解datagridview的条件查询问题
private void ShowDataGridView(){
SQL_conn();
if (comboBox1.SelectedIndex == -1 && comboBox2.SelectedIndex == -1)
{
cmdtext = "select ReiNumber as 识别码,ReiDate as 日期,Department as 部门,name as 出差人,Reason as 出差事由,Cashier as 出纳,Payee as 收款人,TotalRei as 金额 from TravelExpense2";
}
else
{
if (comboBox1.SelectedIndex == -1&& comboBox2.SelectedIndex != -1)
{
cmdtext = "select ReiNumber as 识别码,ReiDate as 日期,Department as 部门,name as 出差人,Reason as 出差事由,Cashier as 出纳,Payee as 收款人,TotalRei as 金额 from TravelExpense2 where name = " + comboBox2.Text;
}
if (comboBox1.SelectedIndex != -1&& comboBox2.SelectedIndex == -1)
{
cmdtext = "select ReiNumber as 识别码,ReiDate as 日期,Department as 部门,name as 出差人,Reason as 出差事由,Cashier as 出纳,Payee as 收款人,TotalRei as 金额 from TravelExpense2 where Department = " + comboBox1.Text;
}
if(comboBox1.SelectedIndex != -1&& comboBox2.SelectedIndex != -1)
{
cmdtext = "select ReiNumber as 识别码,ReiDate as 日期,Department as 部门,name as 出差人,Reason as 出差事由,Cashier as 出纳,Payee as 收款人,TotalRei as 金额 from TravelExpense2 where Department = '" + comboBox1.Text + "' and name=" + comboBox2.Text;
}
}
SQLiteDataAdapter sda = new SQLiteDataAdapter(cmdtext, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "TravelExpense2");
this.dataGridView1.DataSource = ds.Tables["TravelExpense2"];
dataGridView1.Visible = true;
conn.Close();
}
执行时,总是提示数据库表中没有combobox控件中选中的值,请问应该怎么修改?感激不尽!