首页 新闻 赞助 找找看

用dataset可以用datatable不行为杀

0
悬赏园豆:5 [已关闭问题] 关闭于 2008-10-25 19:28

 private DataTable dt;
       // private DataSet dsScore;
        private void Frm5_6_Load(object sender, EventArgs e)
        {
            con.conDataBase();
            string sql = "select * from score";
            SqlCommand sqlCommand = new SqlCommand(sql ,con.coon );
            SqlDataAdapter da = new SqlDataAdapter(sql, con.coon);
           dt = new DataTable();
            //dsScore=new DataSet() ;
            da.Fill(dsScore,"score");
            textBox1.DataBindings.Add(new Binding("Text", dt, "score.studID"));
            dataGridView1.DataSource = dt;
            dataGridView1.DataMember = "score";
           


        }

不行

 private DataTable dt;
        private DataSet dsScore;
        private void Frm5_6_Load(object sender, EventArgs e)
        {
            con.conDataBase();
            string sql = "select * from score";
            SqlCommand sqlCommand = new SqlCommand(sql ,con.coon );
            SqlDataAdapter da = new SqlDataAdapter(sql, con.coon);
            dt = new DataTable();
            dsScore=new DataSet() ;
            da.Fill(dsScore,"score");
            textBox1.DataBindings.Add(new Binding("Text", dsScore, "score.studID"));
            dataGridView1.DataSource = dsScore;
            dataGridView1.DataMember = "score";
           


        }

可以运行,为啥,大哥们答下

问题补充: 对不起各位, da.Fill(dsScore,"score"); 写错了 应该是 da.Fill(dt); 改完了也不行
阿乐的主页 阿乐 | 初学一级 | 园豆:105
提问于:2008-10-22 22:57
< >
分享
所有回答(4)
0

dataGridView1.DataSource = dt;dt里面没有数据呀~

Astar | 园豆:40805 (高人七级) | 2008-10-22 23:17
0

上面一段程序,你那一行 da.Fill(dsScore,"score"); 不会报错?你这里还是填充了 dsScore ,试着把这里的 dsScore 改成 dt ,没有问题的

丁学 | 园豆:18730 (专家六级) | 2008-10-23 08:45
0

dt = new DataTable();
            //dsScore=new DataSet() ;
            da.Fill(dsScore,"score");
            textBox1.DataBindings.Add(new Binding("Text", dt, "score.studID"));
---以上没有看出有填充DataTable数据的动作

RicoRui | 园豆:3663 (老鸟四级) | 2008-10-23 09:33
0

自己打个点,看填充的DT里面有记录没有,看DT有没有score.studID字段,就知道为什么了

与非门 | 园豆:205 (菜鸟二级) | 2008-10-24 15:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册