1

我有一个使用 ms Access 数据库的 VB.NET 应用程序。但是现在数据库被转换为文本文件,数据库的字段通过数据表显示。问题是程序的功能之一不能正常工作,在以前的格式中没有显示任何问题。它是一个查询功能(myStr = "SELECT ID, word FROM Words WHERE " & myval & " ORDER BY id, [word] ASC")。请帮助我。该函数的代码如下所示。

Function ShowWords(ByRef Mybox As ListView, ByVal myval As String, Optional ByVal track As Integer = 0) As Boolean
        If track = 0 Then
            If Len(myval) = 1 Then myval = "len(word)>=1 and len(word)<=40 and left(word, " & Len(myval) & ")= '" & myval.Substring(0, 1) & "'" 'myval.Substring(1) & "'"
            If Len(myval) = 2 Then myval = "len(word)>=2 and len(word)<=45 and left(word, " & Len(myval) & ")= '" & myval.Substring(0, 2) & "'"
            If Len(myval) = 3 Then myval = "len(word)>=3 and len(word)<=50 and left(word, " & Len(myval) & ")= '" & myval.Substring(0, 3) & "'"
            If Len(myval) = 4 Then myval = "len(word)>=4 and len(word)<=65 and left(word, " & Len(myval) & ")= '" & myval.Substring(0, 4) & "'"



 Try
                lvWords.Items.Clear()
                If myval = "" Then
                    Exit Function
                End If
                Dim myStr As String = Nothing
                myStr = "SELECT ID, word FROM Words WHERE " & myval & " ORDER BY id, [word] ASC"

                Dim objCmd As New OleDbCommand(myStr, objConn)
                Dim rs As OleDbDataReader = objCmd.ExecuteReader
                If rs.HasRows Then
                    Dim xItem As ListViewItem
                    Do While rs.Read
                        xItem = Mybox.Items.Add(rs("ID"), IIf(IsDBNull(rs("word")), "", rs("word")), "")
                    Loop
                Else
                    ShowWords = False
                    Exit Function
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
                ShowWords = False
                Exit Function
            End Try
        ElseIf track = True Then
            ShowWords = track
            Exit Function
        End If
        ShowWords = True
    End Function
4

0 回答 0