1

我正在根据访问数据库中的复选框(是/否)进行 Datagridview 过滤。

我的代码---------------------------

{
    OleDbConnection baglanti = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Burak YEŞİLYURT\Desktop\secret.accdb");
    OleDbCommand komutcu;
    OleDbDataAdapter adpt;
    DataSet ds;
    public Form1()
    {
        InitializeComponent();
        baglanti.Open();
        komutcu = new OleDbCommand("SELECT * FROM todo", baglanti);
        adpt = new OleDbDataAdapter(komutcu);
        ds = new DataSet();
        adpt.Fill(ds);
        dataGridView1.DataSource = ds.Tables[0];
        adpt.RowUpdated += adpt_RowUpdated;
        this.dataGridView1.Columns["id"].Visible = false;
        this.dataGridView1.Columns["zaman"].Visible = false;


        this.dataGridView1.Columns["todo"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
    }

    private void Form1_Load(object sender, EventArgs e)
    {

        baglanti.Open();
        komutcu = new OleDbCommand("SELECT * FROM todo", baglanti);
        adpt = new OleDbDataAdapter(komutcu);
        ds = new DataSet();
        adpt.Fill(ds);
        dataGridView1.DataSource = ds.Tables[0]; 




    }
    public void adpt_RowUpdated(object sender, OleDbRowUpdatedEventArgs e)
    {
        if (e.RecordsAffected == 0)
        {
            e.Row.RowError = "Tutarlılık ihlali: UpdateCommand, beklenen 1 kaydın 0 kaydını etkiledi.";

            // Hatalı satır üzerinde işlem yapılmadan es geçiliyor.
            e.Status = UpdateStatus.SkipCurrentRow;
        }
    }

    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        OleDbCommandBuilder komut = new OleDbCommandBuilder(adpt);
        DataSet yeni = new DataSet();
        yeni = ds.GetChanges(DataRowState.Modified | DataRowState.Added);

        adpt.Update(yeni.Tables[0]);
    }

    private void only_cntr_CheckStateChanged(object sender, EventArgs e)
    {
        ds.Tables["todo"].DefaultView.RowFilter = "state = 'true'"; //// Error this line
    }

当我调试时,我收到此错误“对象引用未设置为对象的实例。” 我在哪里失踪?任何帮助我都会很高兴。谢谢

4

1 回答 1

0

当然,您的意思是"state = true""state =-1"不能将布尔值设置为文本值。

于 2012-08-17T10:31:36.590 回答