拆分句子并从数据库中的句子中搜索每个相关的单词字母,并在datagridview中显示 [英] Split the sentence and search every related letter of words from sentence in database and display in datagridview

查看:103
本文介绍了拆分句子并从数据库中的句子中搜索每个相关的单词字母,并在datagridview中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将一个句子放在一个文本框中,所有单词将像谷歌搜索一样逐一检查,并且它将显示所有相关数据(表示例如,如果我将输入一句话``嗨!欢迎来到印度''然后通过检查数据库中的每个单词将显示所有相关数据.结果可以显示india单词中的所有相关数据意味着它可以显示所有相关的``in''或``ind ia''或``nd在我的以下代码中,它正在修饰句子并显示特定单词的所有数据,但未显示相关单词的相关数据意味着如果我接受``欢迎来到印度'',它将应该过滤"in"或"dia"中的数据.

我的编码是:

if i will put one sentence in one textbox that all the words will check one by one like google search.and it will display all related datas(means Ex-If i will put one sentence ''Hi ! welcome to india'' then it will display all related data by checking every words in database.the result can display all the related data means in the word india means it can display all related ''in'' or ''ind ia'' or ''nd'' in datagridview ) in datagridview.In my following coding it is spiliting the sentence and displaying all the data of particular word but it is not displaying the related data of related word means if i will take ''wellcome to india'' then it should filtrate the datas of ''in'' or ''dia''.

My Coding is:

private void btnSearch_Click(object sender, EventArgs e)
{
    try
    {
        string commaDelimited = textBox1.Text;
        string[] year = commaDelimited.Split(new char[] { });
        /////////////////////////////////////////
        //string[] r = { "TV", "Radio", "Coal" };
        string filter = string.Empty;
        foreach (string name in year)
        {
            if (filter.Length > 0)
            {
                filter += ",";
            }
            filter += string.Format("'{0}'", name);
        }
        SqlDataAdapter adp;
        DataSet ds = new DataSet();
        adp = new SqlDataAdapter("Select * from EMP_DET where FName IN (Like '%(" + filter + ")%')", con);
        adp.Fill(ds, "EMP_DET");
        dataGridView1.DataSource = ds.Tables[0].DefaultView;
    }
    catch
    { }
}

推荐答案

SQL LIKE运算符不能那样工作-参见此处:http://www.w3schools.com/sql/sql_like.asp [
The SQL LIKE operator does not work like that - see here: http://www.w3schools.com/sql/sql_like.asp[^]

Instead, you need to build your command with a range of conditions:
SELECT * FROM EMP_DET WHERE FName LIKE %word1% OR FName LIKE %word2%


这篇关于拆分句子并从数据库中的句子中搜索每个相关的单词字母,并在datagridview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆