不同的“选择” MYSQL 中带有“dtTable.Select”的语法在.NET中

发布于 2024-11-17 05:13:54 字数 1014 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倚栏听风 2024-11-24 05:13:54

DataTable.Select 不会那样工作。它只接受其列上的过滤器,其语法类似于 sql 中的 where 子句语法。

示例:

dtTable.Select('operator_id = 1')

将返回 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:

dtTable.Select('operator_id = 1')

will return all rows in dtTable having operator_id = 1

For more informations:

Filter syntax

DataTable.Select Method

瞎闹 2024-11-24 05:13:54

您对 Select 在 Datatable 对象上的工作方式有误,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 一个不错的教程。

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

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)

See http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-4 for a decent tutorial.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文