Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Continuing Access Query Dilemma in VB.Net
Message
General information
Forum:
ASP.NET
Category:
Databases
Title:
Continuing Access Query Dilemma in VB.Net
Miscellaneous
Thread ID:
01060972
Message ID:
01060972
Views:
42
Ok, I've tried the various forms of the "LIKE" clause everyone has presented so far,
with no luck.

In my code below, the value of sSQLCommand is:
" select CategoryName from Categories where CategoryName like 'E*'"
If I hardcode the query string to:
" select CategoryName from Categories where CategoryName = 'Electronic'"
it works fine.



The unhandled exception error occurs on the line:
sRecVal = oReader.GetValue(0)
Here is my code.
    Private Function DoSearch(ByVal sChar As String) As Boolean

        'The TextBox.KeyPress passes in the value e.KeyChar.ToString() 

        ' Define variables
        Dim sRecVal As String = ""          ' Variable to hold the value of the record
        Dim sSQLCommand As String = ""      ' The SQL Command
        Dim sTextVal As String = ""         ' The contents of the textbox
        Dim oCommand As OleDbCommand        ' The command object
        Dim oReader As OleDbDataReader      ' The data reader object

        ' Get the value of the textbox, removing any leading or trailing spaces
        ' including the last character typed. The value sChar was passed in
        ' from the KeyPress event
        sTextVal = txtText.Text.Trim() & sChar

        ' Form the SQL command
        sSQLCommand = " select " & _sSearchField & _
                      " from " & _sSearchAlias & _
                      " where " & _sSearchField & " like '" & _
                      sTextVal & "*'"

        ' Create the command object, passing the SQL quert string and a reference
        ' to the connection object
        oCommand = New OleDbCommand(sSQLCommand, _oConnection)

        ' Execute the command to get the data
        oReader = oCommand.ExecuteReader()

        ' Read in the data. Only need the first occurance of the string
        oReader.Read()
        sRecVal = oReader.GetValue(0)

        If sRecVal <> "" Then

            txtText.Text = sRecVal

        End If

    End Function
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform