不同的“选择” MYSQL 中带有“dtTable.Select”的语法在.NET中
我使用 MySQL 查询浏览器尝试了下面的“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
I tried "SELECT" MYSQL syntax below using MySQL Query Browser, work normally. When I used this syntax into dtTable.Select(), error is "Syntax error on expression". Please help me, Thanks.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DataTable.Select
不会那样工作。它只接受其列上的过滤器,其语法类似于 sql 中的 where 子句语法。示例:
将返回
dtTable
中具有operator_id = 1
的所有行有关详细信息:
过滤器语法
DataTable.Select 方法
DataTable.Select
does not work like that. It just accepts a filter on it's columns with a syntax like the where clause syntax in sql.Example:
will return all rows in
dtTable
havingoperator_id = 1
For more informations:
Filter syntax
DataTable.Select Method
您对 Select 在 Datatable 对象上的工作方式有误,http://msdn.microsoft .com/en-us/library/det4aw50.aspx
您需要使用类似的内容,
请参阅http://www.vbmysql.com/articles /vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-4 一个不错的教程。
You are mistaken in how Select works on the Datatable object, http://msdn.microsoft.com/en-us/library/det4aw50.aspx
You need to be using something along these lines
See http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-4 for a decent tutorial.