2012-10-02 6 views
-1

나는 프로그래밍 할 때 새로운데, 사용자가 MySQL의 다양한 데이터 테이블을 선택, 삽입, 업데이트 및 삭제할 수있는 기본 VB.NET 응용 프로그램에서 작업하고있다.vb.net mysql combobox show tables

내가 겪고있는 문제는 하나의 특정 데이터베이스에서 모든 테이블 이름으로 콤보 박스를 채워야하므로 사용자가 작업 할 데이터베이스 테이블을 선택할 수 있습니다. 내 코드는 효과가있을 것이라고 생각했지만 앱을 실행할 때 빈 컴보 박스 만 얻었습니다.

내 코드에 무엇이 잘못 되었습니까?

미리 감사드립니다.

코드 :

Private Sub TableList_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles TableList.SelectedIndexChanged 

    Try 

     command = New MySqlCommand 
     dt = New DataTable 
     adapter = New MySqlDataAdapter 

     If (conn.State = ConnectionState.Closed) Then 
      setConnection() 
     End If 

     command.Connection = conn 
     command.CommandText = "SHOW TABLES" 

     adapter.SelectCommand = command 
     reader = command.ExecuteReader 

     'adapter.Fill(dt) 
     dt.Load(reader) 

     TableList.DataSource = dt 
     TableList.DisplayMember = "Tables_in_sampledata" 'What is displayed 
     TableList.ValueMember = "Tables_in_sampledata" 'The ID of the row 

    Catch ex As MySqlException 
     MessageBox.Show("Error1: " & ex.Message) 
    Finally 
     reader.Close() 
     conn.Close() 
    End Try 

End Sub 
+0

을 사용하여 어떤 오류의 당신이받을 수 있나요? –

답변

0

대신 SHOW TABLES의 다음 쿼리

SELECT DISTINCT TABLE_NAME 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA='YourDatabase'; 
+0

안녕하세요, John, 도와 주셔서 감사합니다. 귀하의 질의를 시도했지만 아무 것도하지 않았습니다 - 나는 여전히 빈 콤보 박스를 얻고 있습니다. 심지어 "SELECT * FROM 'databaseName'"과 같은 기본적인 SQL 쿼리를 시도해도 여전히 아무것도 얻지 못합니다. – phoeberesnik

+0

@ user1713373 데이터 소스를 설정하기 위해 데이터 세트의 데이터 테이블을 지정하지 않았습니다. 예,'TableList.DataSource = dt.Tables [0]' –

+0

@ user1713373 [여기를 클릭하십시오] (http://msdn.microsoft.com/en-us/library/w67sdsex.aspx) –