I want to search value from database and delete value from databaseshow. I can Search and but when I click the delete button its give me the following Error:

Syntex error:missing operand after '='.

Here is my code:

private void sID_textBox7_TextChanged_1(object sender, EventArgs e)
        {
            try
            {
                BindingSource bs = new BindingSource();
                bs.DataSource = dataGridView4.DataSource;
                bs.Filter = "[Product ID]=" + sID_textBox7.Text.ToString();
                dataGridView1.DataSource = bs;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
有帮助吗?

解决方案

You have just missed the ' before and after the filter value.

[Product ID] = SomeText should be [Product ID] = 'SomeText'

private void sID_textBox7_TextChanged_1(object sender, EventArgs e)
    {
        try
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = dataGridView4.DataSource;
            bs.Filter = "[Product ID]=" + "'" + sID_textBox7.Text + "'";
            dataGridView1.DataSource = bs;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

See BindingSource.Filter Property

EDIT

Writing sID_textBox7.Text.ToString() has no sens. .Text property returns a String, no need to use .ToString().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top