Results 1 to 2 of 2

Thread: [RESOLVED] Dynamic SQL Challenge...

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95

    [RESOLVED] Dynamic SQL Challenge...

    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:
    1. Public Function ClientFindTorrents(ByVal keywords() As String) As Torrent()
    2.  
    3.         Dim DynamicSQL As New System.Text.StringBuilder( _
    4.         "SELECT DISTINCT ID, Time, Tracker, TrackerType, Hash, Section, Name, " & _
    5.         "Description, Size, Seeds, Peers, InfoUrl " & _
    6.         "FROM AvailableTorrents " & _
    7.         "WHERE ")
    8.  
    9.         Dim i As Integer
    10.         For i = 1 To keywords.Length
    11.  
    12.             DynamicSQL.Append("Name LIKE '%" + keywords(i - 1) + "%' ")
    13.             If Not i = keywords.Length Then DynamicSQL.Append("OR ")
    14.  
    15.         Next
    16.  
    17.         Dim con As New SqlConnection(ConnectionString)
    18.         Dim cmd As New SqlCommand(DynamicSQL.ToString, con)
    19.         Dim r As SqlDataReader
    20.  
    21.         Dim Torrents As New ArrayList
    22.  
    23.         ' 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
    Last edited by Kt3; May 17th, 2004 at 11:55 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width