Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Continuing Access Query Dilemma in VB.Net
Message
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
01060972
Message ID:
01061113
Vues:
11
I have tried the "%" already. It did not work.


>I really think that you should replace the * with a %. When you are into Access querying the data, you have to use the * but when you use ADO/ADO.Net, it has to be a %.
>
>
>
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform