使用唯一的critera查找数据表中的第一行

时间:2019-01-10 16:48:11

标签: vb.net ms-access

我在Microsoft Access中有一个数据表,其中有两列:

+-----+-------------+
| Row | Status      |
+-----+-------------+
| 1   | In-Progress |
| 2   | In-Progress |
| 3   | In-Progress |
| 4   | TBR         |
| 5   | TBR         |
| 6   | TBR         |
+-----+-------------+

我需要查询表,以便查询返回第4行。我想知道数据表中状态为TBR的第一行是什么。 VB中的编码非常新。

Public Function FindFirstActiveRow() As Integer
    Dim inum As Integer
    inum = 1

    Dim myconnection As OleDbConnection = New OleDbConnection
    Dim query As String = "Select [ROW] From Table3 where [STATUS]='TBR', AND [ROW]= (select MIN(ROW) from table 3);"
    Dim dbsource As String = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=S:\Docs\PRODUCTION\Shop Manager\Shop_Manager\Shop_Manager\Database2.accdb;")
    Dim conn = New OleDbConnection(dbsource)
    Dim cmd As New OleDbCommand(query, conn)

    Try
        conn.Open()
        Dim myreader As OleDbDataReader = cmd.ExecuteReader()
        myreader.Read()
        FindFirstActiveRow = Val(myreader("ROW"))

        conn.Close()
    Catch ex As OleDbException
        MessageBox.Show("Error Pull Data from Table3")
        FindFirstActiveRow = 1
    End Try

End Function

1 个答案:

答案 0 :(得分:0)

以下是两种可能的方法:

Stream
import foo.Stream
val x: Stream[_] = ??? // this variable has type `foo.Stream`

// Here we have another import of a class with the same name.
// This shadows the first import, so any occurence of `Stream`
// does from now on refer to `bar.Stream`.
import bar.Stream
val x: Stream[_] = ??? // This variable has type `bar.Stream`