JAI MATADI all . .
m trying to find the person (user) through his/her age stored in sql database 3.5 in ASP.NET 4.0 (VS 2010) ..
in my sql database i have (age named in int) in which the users age already defined ..
i have SEARCH.ASPX page and a RESULT.ASPX page .. and m trying to fetch it through querystring .. here is my code ..
---------------------------------------
SEARCH.ASPX
-------------------------
<form id="form1" runat="server">
<div>
From : <asp
ropDownList ID="age1" 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="age2" 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>
<asp:Button ID="searchage" runat="server" Text="Search" onclick="searchage_Click"
</div>
</form>
---------------------------
search.aspx.cs
--------------------------
protected void searchage_Click(object sender, EventArgs e)
{
Response.Redirect("result.aspx?fromage=" + age1.SelectedItem.Text.ToString() + "&toage=" + age2.SelectedItem.Text.ToString());
}
---------------------------------------------
now
result.aspx.cs
-----------------------
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class result : System.Web.UI.Page
{
public string connstr = @"my conn string";
protected void Page_Load(object sender, EventArgs e)
{
int fromm, to;
//gender = (Request["gender"].ToString());
fromm = Convert.ToInt32(Request["fromage"].ToString());
to = Convert.ToInt32(Request["toage"].ToString());
SqlConnection conn1 = new SqlConnection(connstr);
conn1.Open();
string qry1;
qry1 = "select * from signup where age<=" + fromm + " ";
SqlCommand cmd1 = new SqlCommand(qry1, conn1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count != 0)
{
DataSet ds1 = new DataSet();
da1.Fill(ds1, "table2");
int i;
i = Convert.ToInt32(ds1.Tables["table2"].Rows[0][28].ToString());
Response.Write(i);
}
else
{
Response.Write("Value not found");
}
conn1.Close();
}
}
}
}
-----------------------------------------------
when m going RESULT.ASPX page at run time m getting the reply "VALUE NOT FOUND" msg although i have a user whose age is 21 and m selecting between 19 to 25 ..
i know i m making a mistake in this
------------------
m trying to find the person (user) through his/her age stored in sql database 3.5 in ASP.NET 4.0 (VS 2010) ..
in my sql database i have (age named in int) in which the users age already defined ..
i have SEARCH.ASPX page and a RESULT.ASPX page .. and m trying to fetch it through querystring .. here is my code ..
---------------------------------------
SEARCH.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

<asp:Button ID="searchage" runat="server" Text="Search" onclick="searchage_Click"
</div>
</form>
---------------------------
search.aspx.cs
--------------------------
protected void searchage_Click(object sender, EventArgs e)
{
Response.Redirect("result.aspx?fromage=" + age1.SelectedItem.Text.ToString() + "&toage=" + age2.SelectedItem.Text.ToString());
}
---------------------------------------------
now
result.aspx.cs
-----------------------
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class result : System.Web.UI.Page
{
public string connstr = @"my conn string";
protected void Page_Load(object sender, EventArgs e)
{
int fromm, to;
//gender = (Request["gender"].ToString());
fromm = Convert.ToInt32(Request["fromage"].ToString());
to = Convert.ToInt32(Request["toage"].ToString());
SqlConnection conn1 = new SqlConnection(connstr);
conn1.Open();
string qry1;
qry1 = "select * from signup where age<=" + fromm + " ";
SqlCommand cmd1 = new SqlCommand(qry1, conn1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count != 0)
{
DataSet ds1 = new DataSet();
da1.Fill(ds1, "table2");
int i;
i = Convert.ToInt32(ds1.Tables["table2"].Rows[0][28].ToString());
Response.Write(i);
}
else
{
Response.Write("Value not found");
}
conn1.Close();
}
}
}
}
-----------------------------------------------
when m going RESULT.ASPX page at run time m getting the reply "VALUE NOT FOUND" msg although i have a user whose age is 21 and m selecting between 19 to 25 ..
i know i m making a mistake in this
------------------