deva nathan

deva nathan

  • NA
  • 74
  • 18.2k

AutoCompleteExtender with two database fields

Nov 28 2012 5:45 AM
i am using AutoCompleteExtender in asp.net ,it's working correctly when i have one column name in the webservice but it's not working when i have in  two column

eg (it's working)

 public List<string> GetCountries(string prefixText)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Town where  Catatory  like '%'+@Name+'%' ", con);
        cmd.Parameters.AddWithValue("@Name", prefixText);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        List<string> CountryNames = new List<string>();

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            CountryNames.Add(dt.Rows[i][4].ToString());
          

        }
        return CountryNames;
    }


eg(it's not working)

 public List<string> GetCountries(string prefixText)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Town where  Catatory  like '%'+@Name+'%' or Title like '%' +@Name+'%'", con);
        cmd.Parameters.AddWithValue("@Name", prefixText);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        List<string> CountryNames = new List<string>();

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            CountryNames.Add(dt.Rows[i][4].ToString());
            CountryNames.Add(dt.Rows[i][3].ToString());

        }
        return CountryNames;
    }


Answers (1)