Problem with my Search when using dropdownlists

Last post 07-04-2009 2:28 PM by srinivaskotra. 1 replies.

Sort Posts:

  • Problem with my Search when using dropdownlists

    07-04-2009, 12:41 PM
    • Member
      point Member
    • Etarnalazure
    • Member since 07-03-2009, 10:35 AM
    • Posts 16

     i have made a seach for my homepage so the users can seach for people they want to chat with but ive been sitting with this problem for a while now, when im using normal text boxes its easy enough and im not really having any problems but then i go over to saying it have to count in the drop down list so people can click if they want to seach for all the female members or male members i have done this so far:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ddlGender.Items.Add(New ListItem("--All--", 0))

    ddlGender.Items.Add(New ListItem("Female", 1))

    ddlGender.Items.Add(New ListItem("Male", 2))

    End Sub

     

     

    and ive made a class as well:

    Public Function AdvancedSearch(ByVal pro As SearchPro) As DataTable

    Dim objData As New DataAccess

    Dim strSQL As String = "select fldID,fldusername,fldage,fldname,fldgender,fldlastname from tbllogin where (fldGender like ?GenderSearch) and (fldusername like ?keyword and fldname like ?keyword) and (fldage>=?minAge and fldage<=?maxAge)"

    Dim objCMD As MySqlCommand = New MySqlCommand(strSQL)

    objCMD.Parameters.Add("?keyword", MySqlDbType.VarChar).Value = "%" & pro.Keyword & "%"

    objCMD.Parameters.Add("?minAge", MySqlDbType.Int32).Value = pro.minAge

    objCMD.Parameters.Add("?maxAge", MySqlDbType.Int32).Value = pro.maxAge

    objCMD.Parameters.Add("?GenderSearch", MySqlDbType.Int32).Value = pro.GenderSearch

    Return objData.GetData(objCMD, _con

     

  • Re: Problem with my Search when using dropdownlists

    07-04-2009, 2:28 PM

     hi,

    write your like % code in your stored procedure rather than sending as a parameter.

    change this line

    objCMD.Parameters.Add("?keyword", MySqlDbType.VarChar).Value = "%" & pro.Keyword & "%"

    to

    objCMD.Parameters.Add("?keyword", MySqlDbType.VarChar).Value =  pro.Keyword.Tostring();

    and write your search with like in your stored procedure.

    Thanks :)

     

    Remember to click “Mark as Answer” on the post, if it helps you. Because It helps others to find the solution.

    Srinivas Kotra.


Page 1 of 1 (2 items)