标题:动态数据集
只看楼主
jasonxie
Rank: 1
等 级:新手上路
威 望:2
帖 子:225
专家分:0
注 册:2007-3-19
 问题点数:0 回复次数:0 
动态数据集
是关于查询SQL 数据库当中一个表的。有一个表Score,它的属性是Class(班级),Course(课程),Score(成绩).在一个窗口上,有个班级的combo控件,还有一个课程的combo控件,以及一个datagridview控件。我想实现的是动态的数据集,让datagridview只输出我在combo控件中符合条件的班级和课程的成绩。我编了一段代码,可以它每次都是提醒没有找到任何数据,当然datagridview中也不能显示任何数据。下面我把代码贴出来,各位帮忙看看,我不知道哪里不对啦~~~谢谢  

private DataView dataviewScore = new DataView();
private string selectStr = null;





   private void btnCheck_Click(object sender, EventArgs e)
        {
            try
            {
                conn1.Open();
                dataviewScore.Table = dataSetScoreCheck.Tables["Score"];//设置dataview的筛选条件
                dataviewScore.RowFilter = SearchSrt_Made();
                dataGridView1.DataSource = dataviewScore;
            }
            catch (Exception E)
            {
                MessageBox.Show(E.ToString());
            }
            finally
            {
                conn1.Close();
            }
            if (dataviewScore.Count == 0)
            {
                MessageBox.Show("没有符合条件的记录", "没有记录",
                MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboClass.Text = "";
                comboCourse.Text = "";
            }

        }
        private string SearchSrt_Made()
        {
            string searchStr = null;
            bool first = true;
            if ( != null)
            {
                searchStr = "Class=" + "'" + comboClass.Text + "'";
                first = false;
                selectStr = "班级名称:" + comboClass.Text;
            }
            if ( != null)
            {
                if (first)
                {
                    searchStr = "Course=" + "'" + comboCourse.Text + "'";
                    first = false;
                    selectStr = "课程名称:" + comboCourse.Text;
                }
                else
                {
                    searchStr = searchStr +
                        " and Course=" + "'" + comboCourse.Text + "'";
                    selectStr += "课程名称" + comboCourse.Text;
                }
            }
      

            return searchStr;
        }
搜索更多相关主题的帖子: 数据集 动态 
2007-11-25 16:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-188281-1-1.html




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

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