如何在具有空格字符的字段名中过滤datagridview? [英] How to filter datagridview across field name which has space character?
问题描述
这是我的sql查询:
SELECT SF.ID,SF.TARIH AS'TARİH' M.A AS'MÜŞTERİADI'FROM TABLE1 SF AND TABLE2 M
这些列名称具有土耳其语和空格你看到的字符当我尝试过滤datagridview时,我使用这个代码:
(datagridview.DataSource as DataTable).DefaultView.RowFilter =
string.Format('MÜŞTERİADI'LIKE'%{0}%',textbox.Text.ToUpper());
它不工作。如果我在sql查询中调用列名称,就像这样 M.AD AS'MAD'
,并在代码如下MAD LIKE'%{0} %'
它有效。但我需要调用列名称为'MÜŞTERİADI'
。我怎样才能做到这一点? Thx为任何帮助。
最后我发现了。过滤类似于使用sql查询。如果有空格字符只需要将['和']'字符添加到列名。在我的情况下,这样做完美:
(datagridview.DataSource as DataTable).DefaultView.RowFilter =
string。格式([MÜŞTERİADI] LIKE'%{0}%',textbox.Text.ToUpper());
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.
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());
这篇关于如何在具有空格字符的字段名中过滤datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!