How to filter datagridview across field name which has space character?

十年热恋 提交于 2020-01-05 08:19:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!