Question

I am working on Datagridview filtering according to checkbox(yes/no) which is in access database.

my code ---------------------------------------

{
    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
    }

when I debbug I recieved this error "Object reference not set to an instance of an object." Where I'm missing? Any help I'll be pleasure. Thanks

Was it helpful?

Solution

Surely you mean "state = true" or "state =-1" A boolean cannot be set to a text value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top