带有charlist的C#DataGridView.DefaultView.RowFilter

时间:2017-03-29 10:27:37

标签: c# sql datagridview filter rowfilter

我想用[charlist]过滤我的数据网格,就像sql语句一样。

假设我在PlantName中搜索“çiçek”。我的sql选择就像;

SELECT * FROM Plants WHERE PlantName LIKE %[cç][ıi][cç]ek%

这回来了;

çiçek
cicek
cıcek
çıçek
etc....

如何为DataGridView.DefaultView.RowFilter?

执行此操作

1 个答案:

答案 0 :(得分:0)

我找到了办法;

首先,您必须创建搜索索引。例如,我们有一个Plants表,它有一个PlantName字段。只需填充 PlantName 的新字段,并对棘手的字母应用替换操作。

DataBase方面;

替换(更换(更换(更换(更换(更换(更换(更换(更换(更换(更换(更换(更换(替换( PlantName 中, 'C', 'C'),” C ' 'C'), 'I', 'I'), 'I', 'I'), 'I', 'I'), 'G', 'G'), 'G',' G '),' O ' 'O'), 'O', 'O'), 'S', 'S'), 'S', 'S'), 'U', 'U'),' U ','U'),' - ','')AS SEARCH_INDEX

C#side;

private string mReplace(string txt)
    {
        string sonuc;
        if (txt == null) { return ""; }
        txt = txt.Replace(" ", " ");
        txt = txt.Replace("-", " ");
        txt = txt.Replace("ç", "C");
        txt = txt.Replace("Ç", "C");
        txt = txt.Replace("ı", "I");
        txt = txt.Replace("i", "I");
        txt = txt.Replace("İ", "I");
        txt = txt.Replace("ğ", "G");
        txt = txt.Replace("Ğ", "G");
        txt = txt.Replace("ö", "O");
        txt = txt.Replace("Ö", "O");
        txt = txt.Replace("ş", "S");
        txt = txt.Replace("Ş", "S");
        txt = txt.Replace("ü", "U");
        txt = txt.Replace("Ü", "U");
        sonuc = txt.ToUpper();
        return sonuc;
    }

在搜索行中使用此功能,例如;

DataTable1.DefaultView.RowFilter = "SEARCH_INDEX LIKE '*" + mReplace(txtPlantName.Text) + "*'";

http://mehmetgoldenhead.blogspot.com.tr/2017/05/ms-acces-icin-turkce-karakter-replace.html