I being starting to switch to C# from VB.Net.
And to be honest my knowledge from using C is pretty outdated since i used that last years ago.
So i am still figuring things back out.
I wont be surprised if this ends up being a simple fix.

The program goes into runtime, but upon clicking one of the cells in my datagrid i can see the data change in the textboxes.
But it then throws an error.

SyntaxErrorException was unhandled
An unhandled exception of type 'System.Data.SyntaxErrorException' occurred in System.Data.dll
Additional information: Syntax error: Missing operand after ''2'' operator.

        private void FamBestandDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            BindingSource source1 = new BindingSource();
            source1.DataSource = fBDataSet.FamBestand;

            FamilieDossierDataGridView.DataSource = source1;

            source1.Filter = "FamilieNummer'" + famBestandDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString() + "' ";
            naamTextBox.Text = famBestandDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
            voornaamTextBox.Text = famBestandDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
            familieNummerTextBox.Text = famBestandDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString();
            archiefKastTextBox.Text = famBestandDataGridView.Rows[e.RowIndex].Cells[4].Value.ToString();
            notaTextBox.Text = famBestandDataGridView.Rows[e.RowIndex].Cells[5].Value.ToString();
            opmerkingTextBox.Text = famBestandDataGridView.Rows[e.RowIndex].Cells[6].Value.ToString();

        }

Thanks

Dani AI

Generated

For — the exception and a direct fix:
The error "Missing operand after '2' operator" means the Filter string is malformed. A BindingSource uses ADO.NET DataColumn expression syntax, so the expression must include an operator (for example =) and proper quoting for strings. If the column is numeric use no quotes; if it is text wrap the value in single quotes and escape any embedded single quotes by doubling them. Example patterns:

/* numeric */
source1.Filter = "FamilieNummer = " + value;

/* text (escape single quotes) */
var v = value.ToString().Replace("'", "''");
source1.Filter = "FamilieNummer = '" + v + "'";

Practical robustness and lifecycle:
Do not recreate a BindingSource inside the CellClick event — create one at form scope and bind it once (for example in Form.Load). Apply Filter on that shared BindingSource so the filter persists and avoids repeated re-binding. Also validate the click before using row/cell values (check e.RowIndex >= 0 and null-check the cell). As hinted, confirm your column index exists (indexes start at 0). If the actual column name contains spaces or special characters, wrap it in brackets: [FamilieNummer].

Debugging checklist:
Build the filter into a local string variable and inspect it (watch or MessageBox) before assigning to Filter to spot missing quotes or stray characters. If filtering still misbehaves try setting the DataTable.DefaultView.RowFilter directly to isolate UI-binding issues. For partial matches use LIKE with % and remember to escape quotes. These checks will narrow down whether the issue is a syntax problem, a wrong column/type assumption, or a binding-lifetime bug (the latter is what was pointing toward).

Recommended Answers

All 2 Replies

Don't know what your intensions are with source1, but it will be lost after FamBestandDataGridView_CellClick finishes on line 16.

if there are 5 column you should have an index 0-4
if six 0-5

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.