遇到这样的问题,一般是在代入查询之前再一次转成数据库的编码.下面假设我的数据库用的编码为UTF-8
我使用的是JDBC里的Preparedstatement,我不知道C#有没有Preparedstatement,希望对你有所帮助.
String str="select name from mydata where name like ? ";
String tempstr="%"+TextBox.Text;
stmt.set(1,tempstr.getBytes("utf-8"));
stmt.executeQuery();或者用mysql的concat()函数来连接
String str="select name from mydata where name like concat('%',?,'')";
stmt.set(1,(TextBox.Text).getBytes("utf-8));
stmt.executeQuery();当然上面还可以加入binary,或者将其全部变成同一大写或小写.
String str="select name from mydata where binary ucase(name) like concat('%',ucase(?),'')";