问题
I have a datagridview in my winform. I fill it with sql query. I call the column names like that:

This is my sql query:
SELECT SF.ID, SF.TARIH AS 'TARİH', M.AD AS 'MÜŞTERİ ADI' FROM TABLE1 SF AND TABLE2 M
These column names have Turkish and space characters as you see. When i try to filter datagridview, i use this code:
(datagridview.DataSource as DataTable).DefaultView.RowFilter =
string.Format("'MÜŞTERİ ADI' LIKE '%{0}%'", textbox.Text.ToUpper());
It doesn't work. If i call the column name in sql query like that M.AD AS 'MAD'
and in code like that "MAD LIKE '%{0}%'"
it works. But i need to call column name as 'MÜŞTERİ ADI'
. How can i do that? Thx for any help.
回答1:
At last i found it. The filtering is similar to work with sql queries. If there is space characters only need to add '[' and ']' characters to column name. In my case, this works perfectly:
(datagridview.DataSource as DataTable).DefaultView.RowFilter =
string.Format("[MÜŞTERİ ADI] LIKE '%{0}%'", textbox.Text.ToUpper());
回答2:
you can try this.......
(datagridview.DataSource as DataTable).DefaultView.RowFilter =
string.Format("'MÜŞTERİ AD' LIKE 'I%{0}%'", textbox.Text.ToUpper());
来源:https://stackoverflow.com/questions/17503727/how-to-filter-datagridview-across-field-name-which-has-space-character