Hi to all, I am working on an advanced search module. It consist of 6 fields given to user to fill and search. The user can fill any one or two and may be all the fields to search. Some fields are text based and some are float. The logic is that after taking the input, the application should check which fields are filled up by the user. And neglect the fields which are not filled from the sql query. What I did is that, I fetched all the values from the textboxes and the values which are not empty has been added to a arraylist. Now I got the filledup values. But application will know that it is productid, description or what... Please assist me.
protected void Button1\_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings\["newcon"\].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
//find out which feilds are not null, then make search on the basis of those feilds
//Now the feilds which are not empty are:
ArrayList arl = new ArrayList();
if (TextBox1.Text.Trim() != "")
{
arl.Add("productid");
}
if (TextBox2.Text.Trim() != "")
{
arl.Add("sh\_desc");
}
if (TextBox3.Text.Trim() != "")
{
arl.Add("weight");
}
if (TextBox4.Text.Trim() != "")
{
arl.Add("length");
}
if (TextBox5.Text.Trim() != "")
{
arl.Add("width");
}
if (TextBox6.Text.Trim() != "")
{
arl.Add("height");
}
//Now take out the items from the arraylist
for (int i = 0; i <= arl.Count; i++ )
{
if (arl\[i\].ToString().StartsWith("productid"))
{
}
}
cmd.CommandText = "select sh\_desc,productid,price from PRODUCTS where ";
cmd.Connection.Open();
dt = new DataTable();
dt.Columns.Add("REF", typeof(string));
dt.Columns.Add("Description", typeof(string));
dt.Columns.Add("Price", typeof(float));
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
pr\_id = (rdr\["productid"\]).ToString();
testsh\_desc = (rdr\["sh\_desc"\]).ToString();
test\_price = Convert.ToSingle(rdr\[