I want to filter records as per price
I want to retrive data from database what i have to use to retrive data a between , and or an or....
I have following code.... But it dosnt work

 protected void rb1_CheckedChanged(object sender, EventArgs e)
    {
        if (rb1.Checked == true)
        {
            DataView dv = dt.DefaultView;
            dv.RowFilter = "Price>='$ 500' Or Price <='$ 1100'";
            DataList1.DataSource = dv;
            DataList1.DataBind();
        }

    }





I want  to retrive data from database

use datareader to retrieve data from database . like
Select * from (Table) where price >= 500 and price <=1000

The data type is varchar....
i have used following code but its not working...

        if (rb1.Checked == true)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=HP-HP;Initial Catalog=OnlineShop;Integrated Security=True";

            con.Open();
            SqlCommand cmd = new SqlCommand("Select Product_Code, Name,Brand,Price,Image from Pendrive where Price>='$ 0' and Price<='$ 500'", con);
            SqlDataReader dr = cmd.ExecuteReader();
            dt = new DataTable();
            dt.Load(dr);
            DataList1.DataSourceID = null;
            DataList1.DataSource = dt;
            DataList1.DataBind();

        }

Confirm that the dataReader, or the dataTable, actually contains some rows. Does the price column really include the dollar sign and the space between the $ and the price?
Also, is the radioButton set to autoPostBack=true? If not it is possible the code isn't getting called at all.

yes autopost back set to true and also database contain dollar sign and space but still cant get the result....
is the same possible with rowfilter....

Will select clause change if i use datatype nchar insted of varchar.....

It shouldn't. Have you actually typed that SQL statement into SQL studio and had it return a result of more than zero rows? As it appears in your post it should work.

Suppose i create one table named Price and inserted following records
Data type nchar.....

Insert into Price values('$ 100')
Insert into Price values('$ 500')
Insert into Price values('$ 600')
Insert into Price values('$ 700')
Insert into Price values('$ 800')
Insert into Price values('$ 900')
Insert into Price values('$ 1000')
Insert into Price values('$ 1100')
Insert into Price values('$ 1200')
Insert into Price values('$ 1300')
Insert into Price values('$ 1400')
Insert into Price values('$ 1500')

Now i am calling following query

Select * from Price where Price>=N'$ 0' and Price<=N'$ 500'

Then i get following records

Price
$ 100
$ 500
$ 1000
$ 1100
$ 1200
$ 1300
$ 1400
$ 1500

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.