首页 新闻 会员 周边

datagrid 有关问题

0
悬赏园豆:5 [已解决问题] 解决于 2008-10-25 19:29

大哥们,这是咋整的

我想删除一条记录报错了

代码: private SqlDataAdapter da;
        private DataSet dsScore;
        int cur;
        private void Frm5_6_Load(object sender, EventArgs e)
        {
            con.conDataBase();
            string sql = "select * from score";
            SqlCommand sqlCommand = new SqlCommand(sql ,con.coon );
            da = new SqlDataAdapter(sql, con.coon);
           // dt = new DataTable();
            dsScore=new DataSet() ;
           // dt = new DataTable();
           // da.Fill(dt);
         
            da.Fill(dsScore,"score");
            SqlCommandBuilder builder = new SqlCommandBuilder(da);
            this.BindingContext[dsScore, "score"].PositionChanged += new EventHandler(BingingManagerBase_PositionChanged );
            textBox1.DataBindings.Add(new Binding("Text", dsScore, "score.studID"));
           // dataGridView1.DataSource = dt;
            dataGridView1.DataSource = dsScore;
            dataGridView1.DataMember = "score";
           


        }
        private void ShowPosition()
        {
            int iCnt, iPos;
            iCnt = this.BindingContext[dsScore, "score"].Count;
            iPos = this.BindingContext[dsScore, "score"].Position + 1;
            if (iCnt == 0)
            {
                groupBox1.Text = "jgj";
            }
            else
            {
                groupBox1.Text = iPos.ToString() + "of" + iCnt.ToString();
            }
       
       
        }

        private void BingingManagerBase_PositionChanged(object sender, EventArgs e)
        {
            ShowPosition();
        }

      

      

        private void button9_Click(object sender, EventArgs e)
        {
            dsScore.Tables["score"].Rows[this.BindingContext[dsScore, "score"].Position].Delete();
            da.Update(dsScore ,"score");
        }

阿乐的主页 阿乐 | 初学一级 | 园豆:105
提问于:2008-10-24 19:39
< >
分享
最佳答案
0

score表里没有主键?

丁学 | 专家六级 |园豆:18730 | 2008-10-25 07:41
其他回答(2)
0

还是专家厉害,一针见血。

我倒是看这代码的 规范性了 唉 ,差距啊。

常大波 | 园豆:255 (菜鸟二级) | 2008-10-25 14:32
0

从调试提示来看,好像是没有主键所致.SqlCommandBuilder 效率也许不太高.客户端的程序用也许无仿.

Jerry Qian | 园豆:19 (初学一级) | 2008-10-25 15:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册