Modifing code to work with Microsoft Access
Hello Everyone,
I am working on modifying the code in Beginning ASP.NET E-Commerce With Visual Basic .NET and Visual Studio .NET. I am currently in Chapter 5 Searching the Catalog. I have modified the stored procedures into Access queries, instead of one query to decide to search for All Words or Any Words I created two different queries then call them separately in the Catalog class.
So for the queries work in Access and I have written the code to pass in the parameters. Everything is working without thowing any errors, but I don't get any results. Any ideas? (code is below)
Public Function SearchCatalog(ByVal searchString As String, ByVal allWords As String) As OleDbDataReader
' Create the connection object
Dim connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand
' We guard agains bogus values here - if we receive anything
' different than "TRUE" we assume it's "FALSE"
If allWords.ToUpper = "TRUE" Then
' Create and initialize the command object and search all words
command.CommandText = "SearchCatalogAllWords"
command.Connection = connection
command.CommandType = CommandType.StoredProcedure
Else
' Create and initialize the command object and search any words
command.CommandText = "SearchCatalogAnyWords"
command.Connection = connection
command.CommandType = CommandType.StoredProcedure
End If
' We eliminate separation characters
searchString = searchString.Replace(",", " ")
searchString = searchString.Replace(";", " ")
searchString = searchString.Replace(".", " ")
' We create an array which contains the words
Dim words() As String = Split(searchString, " ")
' wordsCount contains the total number of words
Dim wordsCount As Integer = words.Length
' index is used to parse the list of words
Dim index As Integer = 0
' this will store the total number of added words
Dim addedWords As Integer = 0
' We allow a maximum of 5 words
While addedWords < 5 And index < 5
' We add the @searchWord parameters here
If addedWords < wordsCount Then
addedWords += 1
' Add an input parameter and supply a value for it
command.Parameters.Add("@searchWord" + addedWords.ToString, words(index))
Else
addedWords += 1
' Add a blank input parameter
command.Parameters.Add("@searchWord" + addedWords.ToString, "")
End If
index += 1
End While
' Open the connection
connection.Open()
' Return a SqlDataReader to the calling function
Return command.ExecuteReader(CommandBehavior.CloseConnect ion)
End Function
--
Victor Corey
__________________
--
Victor Corey
|