ASP.NET, C# and SQL Server database.
I have a table Students
with a gender
column and photos saved in another table. On the page, I have a dropdown control of which I've bound to the gender value, and a button.
What I want to do is: if the user selects male or female from dropdown control and click the button, all selected photos and records should be displayed in a repeater control..
I've tried using a stored procedure with the query:
select A.*, B.*
from tblStudents A
cross apply
(select top 1 *
from tbl studentImages B
where A.Gender = @Gender and B.ImageID = A.ImageID
But its showing all the records instead of showing only the selected records.
Can anybody help ?
Code behind:
protected void btnsearch_click(onject sender, EventArgs)
{
Int64 Gender = Convert.Toint64(Request.Querystring[Gender]);
String S = ConfigurationManager.onnectionStrings["DBST"]ConnectionStrings;
using(SqlCommand con= new SqlCommand(CS))
{
SqlCommand cmd = new SqlCommand("SP_Data",con)
cmd.commandType = commandType.StoredProcedure;
con.Open();
SqlDataAdapter ada = new SqlDataAdapter(cmd)
DataTable dt = new DataTable();
ada.Fill(dt);
if(dt.Rows.Count !=0)
{
rpterGender.DataSource = dt;
rpterGender.DataBind();
}
}
}
}
You need to use join in Query.
select A.*, B.*
from tblStudents A
join tblstudentImages B on B.ImageID = A.ImageID
where A.Gender = @Gender
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.