Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void textBox1_TextChanged(object sender, EventArgs e)
{
    DataTable dataSet = new DataTable();
    DataView DV = new DataView(dataSet);
    DV.RowFilter = string.Format("select * from classes where title LIKE '%{0}%';", textBox1.Text);
    dataCursuri.DataSource = DV;
}


I want to filter the database table "classes" by column "title".
I made a textbox and the text entered there will filter the column.
(The database I use is PostgreSQL)

I Get an error saying Missing operand after 'classes' operator

I`m asking for some help ,because I can`t figure out how to do it..
Thank you.
Posted
Updated 3-May-14 0:28am
v2

1 solution

thr syntax should be
C#
DV.RowFilter =@"Column1 like '%" + textBox1.Text + "%'" ;
 
Share this answer
 
v2
Comments
Nafeths 3-May-14 6:39am    
Have tried
DV.RowFilter =@"Title like '" + textBox1.Text + "'" ;
and I get "cannot find column [title]"

Also tried to add Tablename.Title and still the same...
DamithSL 3-May-14 6:44am    
how you get data for DataTable? can you show that code?
Nafeths 3-May-14 8:35am    
Finally I figured out what was wrong...
I declared globally the DataTable variable, something like:
DataTable dataSet;

And also changed the row for syntax when getting data for table to look like:
dataSet = new DataTable();

Now I have this:
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataView DV = new DataView(dataSet);
DV.RowFilter = @"Title like '%" + textBox1.Text + "%'" ;
dataClasses.DataSource = DV;
}

Everything works as desired :)
Thank you DamithSL!
DamithSL 3-May-14 8:47am    
you are welcome! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900