Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have shown the search by Products name as below.. i want to add the search by price query in the same code.. how can i add search by prices i.e range 0 to 5000, 5000 to 15000 e.t.c in the same query.. can i use OR command for that.. and i am using the object oriented aapproach here.. how can i get rid from sql concetination.. where to put cmd.Parameter.Add in the code.

I have shown the products by by using like sql query as below

C#
private void Search()
{  
  string query = "Select * from Products where ProductName Like '" + Request.QueryString["Name"] + "%'";
            DataSet ds = obj.fillgrid(query);
  GridView1.DataSource = ds.Tables[0];
  GridView1.DataBind();
}


and i have a fillgrid method in dbcon class as.
C#
public DataSet fillgrid(String query)
       {
           DataSet ds = null;
           try
           {
               SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connectionString);
               ds = new DataSet();
               dataAdapter.Fill(ds, "*.mdb");

           }
           catch (Exception ex)
           {
               // MessageBox.Show(ex.Message);
           }
           return ds;
       }
Posted
Updated 22-Dec-11 12:50pm
v2

1 solution

This is not the perfect solution and it will solve your problem mediately.
Since you are using a gridview and you want filtering and sorting I think this link will help you display what you ask for:

Gridview helper[^]

Secondly for avoiding SQL injections[^] use Parameterized Queries[^].

When you want to add a parameter to your SQL query you use, cmd.Parameter.Add. For better understanding check the provided link here[^]

Good luck,
OI
 
Share this answer
 
v2
Comments
codegeekalpha 22-Dec-11 15:25pm    
???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900