2013-10-12 4 views
0

VB.Net 및 MySql 데이터 공급자를 통해 간단한 Select 문을 실행하면 그리스어 문자열을 검색하는 Mysql 테이블로 어떤 결과도 반환되지 않습니다. MYSQL Ver 5.5.32 VB.Net : 2010그리스어 문자열을 Mysql에서 검색 할 수 없습니다.

전달 된 문자열에 특별한 인코딩이 필요합니까?

PS : 이미 솔루션은 노호 게시 봤어 :

  1. 무엇 인코딩에서 β 문자인가? 입력은 어디에서 왔습니까? 콘솔에서 나온 것이라면 ISO-8859-1이 아닌 UTF-8을 사용해야합니다. - Pekka 웃음 8 월 5 일 8시 5 분

  2. 사용 해보십시오 : mysql_query ("SET NAMES 'utf8 '' '); - 12시 36분 내 코드가 fllowing처럼 보이는

에서 reven 10월 26일 '11 :

Dim ds As New DataSet 
    Dim da As New MySqlClient.MySqlDataAdapter 
    Dim dt As New DataTable 
    Dim utf8Encoding As New System.Text.UTF8Encoding 

    Dim sql, st As String 
    Dim bytes() As Byte 
    Dim com As New MySql.Data.MySqlClient.MySqlCommand("SET NAMES 'utf8'", MysqlConn) 
    com.ExecuteNonQuery() 
    bytes = (Encoding.UTF8.GetBytes(TextBox2.Text)) 
    st = Encoding.UTF8.GetString(bytes) 
    sql = "Select * from Customers where name like '%" & st & "%'".ToString 

    Dim command As New MySqlClient.MySqlCommand(sql, MysqlConn) 

    da.SelectCommand = command 

    da.Fill(ds) 
    MysqlConn.Close() 

    DataGridView1.DataSource = ds.Tables(0) 

고맙습니다 ASP.NET에 VB.NET에서 내 경험에

답변

0

,가

데이터베이스 : 데이터베이스의 데이터 정렬은 UTF-8로 설정되어야합니다.

연결 문자열 : 연결 문자열의 '문자 집합'이 UTF-8로 설정되어 있는지 확인하십시오.

<connectionStrings> 
    <add name="connstr" connectionString="Data Source=127.0.0.1;Database=db_name;User ID=db_user;Password=db_pass;Character Set=utf8;" providerName="MySql.Data.MySqlClient" /> 
</connectionStrings> 

코드 파일 : 모든 코드 파일 인코딩 (서명)을 UTF-8로 저장해야합니다. 이것은 모든 Visual Studio 파일의 기본값입니다. UTF-8로 저장되었는지 확인하는 단계는 here을 참조하십시오.

WinForms 응용 프로그램이 있다고 생각합니다. 따라서 VB 파일이 올바르게 저장되므로 입력 내용이 UTF-8이고 변환 할 필요가 없습니다.

데이터베이스의 데이터 정렬이 UTF-8로만 설정되어있는 경우 입력을 UTF-8에서 db의 인코딩으로 변환해야합니다.

0

MySql 사용에 익숙하지 않습니다. 그러나 UTF-8을 통과하는 것이 문제 일 수 있습니다 (.NET은 문자열에 UTF-16을 사용합니다). 다음과 같이 시도해보세요.

Dim ds As New DataSet 
Dim da As New MySqlClient.MySqlDataAdapter 
Dim dt As New DataTable 

Dim sql, st As String 
sql = "Select * from Customers where name like ?name" 

Dim command As New MySqlClient.MySqlCommand(sql, MysqlConn) 
Dim theName As String = "%" & TextBox2.Text & "%" 
da.Parameters.Add("name", theName) 
da.SelectCommand = command 

da.Fill(ds) 
MysqlConn.Close() 

DataGridView1.DataSource = ds.Tables(0) 

필요하면 줄을 조정하십시오. 예 : 데이터 유형 W 크기가 필요할 수 있습니다.

관련 문제