我用combobox选择显示在datagridview中的表
          switch(comboBox1.SelectedItem.ToString())
            {
                case "表1":
                dataGridView1.DataSource = dJCCDataSet.Tables["t1"];
                break;
                case "表2":
                dataGridView1.DataSource = dJCCDataSet.Tables["t2"];
                break;
            }
现在我想要在显示表1的时候删除其中选中的行,显示表2时删除其中选的行,同时删掉数据库表中的相应行
this.t1TableAdapter.Fill(this.djDataSet.t1)
this.t2TableAdapter.Fill(this.djDataSet.t2)
新手求助各位高手这个删除按钮的内容应该怎么写

解决方案 »

  1.   


    int rowIndex = this.dataGridView1.CurrentRow.Index;//找到当前行下标string tableName = "t1";//取得表名
    if(comboBox1.SelectedItem.ToString() == "表2")
        tableName = "t2";dJCCDataSet.Tables[tableName].Rows[rowIndex].Delete();//在数据集中删除指定行
    this.dataGridView1.DataSource = null; //清空数据源
    if(tableName == "t1")
    {
        this.t1TableAdapter.Update(this.djDataSet.t1);//修改数据库
        this.dataGridView1.DataSource = this.djDataSet.t1;//重新指定数据源
    }
    else
    {
        this.t2TableAdapter.Update(this.djDataSet.t2);
        this.dataGridView1.DataSource = this.djDataSet.t2;}