[英]How to fetch Male or Female from a SQL Server database table column and display the records in a repeater control?
ASP.NET, C# and SQL Server database. ASP.NET,C#和SQL Server数据库。
I have a table Students
with a gender
column and photos saved in another table. 我有一个带有gender
列的表格Students
,并将照片保存在另一个表格中。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.