2014-04-11 73 views
-4

您好我新來的Visual Studio,我總是得到這個錯誤「您的SQL語法錯誤;檢查手冊,對應您的SQL」您的SQL語法錯誤;檢查與您的SQL相對應的手冊

這是我的代碼,你

Public Class Form1 
    Dim MysqlConn As MySql.Data.MySqlClient.MySqlConnection 

    Dim UsersCommand As New MySql.Data.MySqlClient.MySqlCommand 

    Dim UsersAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter 

    Dim UsersData As New DataTable 

    Dim SQL As String 
    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick 

    End Sub 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     MysqlConn = New MySql.Data.MySqlClient.MySqlConnection() 
     ' Define the SQL to prob data from table. 
     SQL = "Select FROM wala" 
     'Connection String 
     MysqlConn.ConnectionString = "server=localhost;" & "user id=Taena;" & "password=Taena;" & "database=wala" 
     Try 
      MysqlConn.Open() 
      UsersCommand.Connection = MysqlConn 
      UsersCommand.CommandText = SQL 
      UsersAdapter.SelectCommand = UsersCommand 
      UsersAdapter.Fill(UsersData) 
      DataGridView1.DataSource = UsersData 

     Catch myerror As MySql.Data.MySqlClient.MySqlException 
      MessageBox.Show("Cannot connect to database1" & myerror.Message) 
     Finally 
      MysqlConn.Close() 
      MysqlConn.Dispose() 

     End Try 
    End Sub 
End Class 

回答

2

你錯過了你想從wala tzable中選擇的列。 *是所有列。嘗試

Select * FROM wala 

,甚至更好地明確你需要這樣的

select id, other_column from wala 
2
Select FROM wala 

你沒有告訴它什麼選擇列 - 嘗試

Select * FROM wala 
0

你需要指定列名或*在選擇查詢的地方。這很簡單。

相關問題