Here's a dynamic sql command that I wrote to be able to take a string array and use it to match a database entry for any word in that string in a specific column.. What I would like to do and failed horribly at doing is to figure out a way to get this to return a result if any of the words are found in TWO columns.
VB Code:
Public Function ClientFindTorrents(ByVal keywords() As String) As Torrent() Dim DynamicSQL As New System.Text.StringBuilder( _ "SELECT DISTINCT ID, Time, Tracker, TrackerType, Hash, Section, Name, " & _ "Description, Size, Seeds, Peers, InfoUrl " & _ "FROM AvailableTorrents " & _ "WHERE ") Dim i As Integer For i = 1 To keywords.Length DynamicSQL.Append("Name LIKE '%" + keywords(i - 1) + "%' ") If Not i = keywords.Length Then DynamicSQL.Append("OR ") Next Dim con As New SqlConnection(ConnectionString) Dim cmd As New SqlCommand(DynamicSQL.ToString, con) Dim r As SqlDataReader Dim Torrents As New ArrayList ' SQL execution code ommited.
Right now it checks to see if the words can be found in the "Name" column. But what if I wanted it to find words in column "Description" also?
Any ideas?
Thanks,
KT




Reply With Quote