C# MySql查询不显示结果

C# MySql查询不显示结果,c#,mysql,sql,datagridview,C#,Mysql,Sql,Datagridview,我有一个字符串,其值如下: a、 b,c,d,e 其思想是使用sql命令在数组中搜索条目。 sql是: select * from pelates where Onoma in (@giorti) 我将a,b,c,d,e转换为'a','b','c','d','e',然后用previus字符串替换@giorti值以填充datagridview。 问题是datagridview保持为空,除非我编辑sql语句并手动给出一个值,如: select * from pelates where Onoma

我有一个字符串,其值如下: a、 b,c,d,e

其思想是使用sql命令在数组中搜索条目。 sql是:

select * from pelates where Onoma in (@giorti)
我将a,b,c,d,e转换为'a','b','c','d','e',然后用previus字符串替换@giorti值以填充datagridview。 问题是datagridview保持为空,除非我编辑sql语句并手动给出一个值,如:

select * from pelates where Onoma in ('Bampis')
如果我这样做,结果会很正常。请注意,我认为有一个编码问题,因为数据是希腊语的 这是我的密码:

 //Diaxorismos onomaton pou giortazoun

        String giorti = label2.Text;
        String[] name = giorti.Split(',');

        for (int i = 0; i < name.Length; i++)
        {
            StringBuilder sb = new StringBuilder(name[i]);
            sb.Insert(0, "'");
            sb.Append("'");
            name[i] = sb.ToString();
            name[i] = name[i];
        }

        String finalName = String.Join(",", name);
        finalName = finalName.Replace(" ", "");
        textBox1.Text = finalName;
        //


        showPelatesPouGiortazounCommand = login.connection.CreateCommand();
        showPelatesPouGiortazounCommand.CommandText = "select * from pelates where Onoma in (@giorti)";
        showPelatesPouGiortazounCommand.Parameters.AddWithValue("@giorti", System.Text.Encoding.UTF8.GetBytes(finalName));
        getPelatesPouGiortazounAdapter = new MySqlDataAdapter(showPelatesPouGiortazounCommand);
        pelatesPouGiortazounDataset = new DataSet();
        getPelatesPouGiortazounAdapter.Fill(pelatesPouGiortazounDataset);
        dataGridView1.DataSource = pelatesPouGiortazounDataset.Tables[0].DefaultView;
//象声虫
字符串giorti=label2.Text;
String[]name=giorti.Split(',');
for(int i=0;i
使用“在集合中查找”功能在逗号分隔的列表中搜索,
或者根据字符串中的值准备和绑定尽可能多的参数

select * from pelates where FIND_IN_SET(Onoma, @giorti)
非常感谢各位朋友! 通过以上添加,我的代码工作得非常好! 以下是最终代码:

 String giorti = label2.Text;
        String[] name = giorti.Split(',');
        String finalName = label2.Text;
        finalName = finalName.Replace(" ", "");
        textBox1.Text = finalName;

        showPelatesPouGiortazounCommand = login.connection.CreateCommand();
        showPelatesPouGiortazounCommand.CommandText = "select * from pelates where FIND_IN_SET(Onoma, @giorti)";
        showPelatesPouGiortazounCommand.Parameters.AddWithValue("@giorti", System.Text.Encoding.UTF8.GetBytes(finalName));
        getPelatesPouGiortazounAdapter = new MySqlDataAdapter(showPelatesPouGiortazounCommand);
        pelatesPouGiortazounDataset = new DataSet();
        getPelatesPouGiortazounAdapter.Fill(pelatesPouGiortazounDataset);
        dataGridView1.DataSource = pelatesPouGiortazounDataset.Tables[0].DefaultView;