| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 563 人关注过本帖
标题:求解datagridview的条件查询问题
只看楼主 加入收藏
快手刘1号
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-3-4
结帖率:0
收藏
 问题点数:0 回复次数:3 
求解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控件中选中的值,请问应该怎么修改?感激不尽!
搜索更多相关主题的帖子: private 识别码 出纳 
2015-03-11 08:40
快手刘1号
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-3-4
收藏
得分:0 
没人会?难道论坛里的都是新手?
2015-03-11 14:41
Maick
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:32
帖 子:251
专家分:1314
注 册:2012-9-21
收藏
得分:0 
sql 语句错了..如果是文本的话要用 ' ' 引起来..我看你只有后面的其中一个用了单引号 ''
2015-03-13 14:30
快手刘1号
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-3-4
收藏
得分:0 
回复 3楼 Maick
恩,前天的时候已经做出来了
2015-03-13 17:29
快速回复:求解datagridview的条件查询问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020142 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved