How do I populate textbox from database based on parameter.
For example I don't want all the data in the database to populate. I just want particular data from a particular user, so I used parameterized query.
But it is not working, all the data in the datbase still populates. Please how can the query be well written?
I used a web method to populate values from database.
public static List<string> SearchCust(string prefixText, int count)
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT [Id], [Tname] FROM [InvoiceTable] where [Tname] LIKE @SearchText + '%' AND CreatedBy = @CreatedBy";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Parameters.AddWithValue("@CreatedBy", createby.Text);
cmd.Connection = con;
con.Open();
List<string> BioCust = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
BioCust.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr["Tname"].ToString(),
sdr["Id"].ToString()));
}
}
con.Close();
return BioCust;
}
}
}