我在下面使用MySQL Query Browser尝试了“SELECT”MYSQL语法,正常工作。当我将此语法用于dtTable.Select()时,错误是“表达式上的语法错误”。请帮帮我,谢谢。
Dim dtTable As DataTable = MyDataset.Tables("machine")
Dim sql As String = String.Format("SELECT product_name, operator_name, totalizer_name
FROM product, operator, totalizer_type, machine
WHERE product.product_id = machine.product_id AND
operator.operator_id = machine.operator_id AND
totalizer_type.totalizer_id = machine.totalizer_id
ORDER BY machine.machine_id ASC;")
Dim rowSearching() As DataRow
rowSearching = dtTable.Select(sql) ' <--- (error in here - "Syntax error on expression")
If rowSearching.Length > 0 Then
For Each dr As DataRow In rowSearching
MessageBox.Show(CStr(dr.Item(0)) & " " & CStr(dr.Item(1)) & " " & CStr(dr.Item(2)))
Next
End If
答案 0 :(得分:2)
DataTable.Select
不起作用。它只是在它的列上接受一个过滤器,其语法类似于sql中的where子句语法。
dtTable.Select('operator_id = 1')
将返回dtTable
中operator_id = 1
答案 1 :(得分:0)
您对“数据表”对象http://msdn.microsoft.com/en-us/library/det4aw50.aspx
的选择方式有误你需要沿着这些方向使用某些东西
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable
Dim SQL As String
conn.ConnectionString = myConnString
conn.Open()
myCommand.Connection = conn
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
请参阅http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-4获取体面的教程。