嗨,我是视觉工作室的新手,我总是收到这个错误"你的SQL语法有错误;查看与SQL#34;
对应的手册这是我的代码,请帮助我谢谢
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
答案 0 :(得分:2)
您错过了要从wala
tzable中选择的列。 *
是所有列。尝试
Select * FROM wala
甚至可以更好地指定您需要的列
select id, other_column from wala
答案 1 :(得分:2)
Select FROM wala
您没有告诉它选择什么 - 尝试
Select * FROM wala
答案 2 :(得分:0)
您需要在select query的位置指定列名或*。这一切都很简单。