JAI MATADI to all ..
m trying to get the user by selecting the persons age FROM & TO
for example (if i select FROM : 19 & To : 25 ) i will be able to see the users between that age only in my gridview .. but m getting problem to do it .. here is my code ..
----------------------------------
page1.aspx
------------
<form id="form1" runat="server">
<div>
From :
<asp
ropDownList ID="from" runat="server">
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
</asp
ropDownList>
To :
<asp
ropDownList ID="to" runat="server">
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
</asp
ropDownList>
<br />
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server">
<EmptyDataTemplate>
No values found
</EmptyDataTemplate>
</asp:GridView>
</div>
</form>
--------------------------------------------
page1.asox.cs
-----------------------
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class page1 : System.Web.UI.Page
{
public string connstr = @"my conn string";
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string qry;
qry = "select * from signup where age<=" + from.SelectedItem.Text.ToString() + " and age>" + to.SelectedItem.Text.ToString() + "";
SqlCommand cmd = new SqlCommand(qry, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "table");
conn.Close();
GridView1.DataSource = ds.Tables["table"];
GridView1.DataBind();
}
}
}
-----------------------------------------------
m getting the NO VALUES FOUND when m running my page and selecting from 19 to 30 although i have users whose age is 21,25,24,26 etc .
and i have age (stored in INT ) only in my sql database .. so which is also not a problem .
tell me what query i should to write here to fetch that ..
any help would be highly and highly appreciated .. thanks a lott ..
m trying to get the user by selecting the persons age FROM & TO
for example (if i select FROM : 19 & To : 25 ) i will be able to see the users between that age only in my gridview .. but m getting problem to do it .. here is my code ..
----------------------------------
page1.aspx
------------
<form id="form1" runat="server">
<div>
From :
<asp

<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
</asp

To :
<asp

<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
</asp

<br />
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server">
<EmptyDataTemplate>
No values found
</EmptyDataTemplate>
</asp:GridView>
</div>
</form>
--------------------------------------------
page1.asox.cs
-----------------------
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class page1 : System.Web.UI.Page
{
public string connstr = @"my conn string";
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string qry;
qry = "select * from signup where age<=" + from.SelectedItem.Text.ToString() + " and age>" + to.SelectedItem.Text.ToString() + "";
SqlCommand cmd = new SqlCommand(qry, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "table");
conn.Close();
GridView1.DataSource = ds.Tables["table"];
GridView1.DataBind();
}
}
}
-----------------------------------------------
m getting the NO VALUES FOUND when m running my page and selecting from 19 to 30 although i have users whose age is 21,25,24,26 etc .
and i have age (stored in INT ) only in my sql database .. so which is also not a problem .
tell me what query i should to write here to fetch that ..
any help would be highly and highly appreciated .. thanks a lott ..