asp.net,c#和sql Server数据库。
我有一个带有gender
列的表Students
,并保存在另一个表中的照片。在页面上,我有一个下拉列表控制,我将其绑定到性别价值和一个按钮。
我想做的是:如果用户从下拉列表控制中选择男性或女性,然后单击按钮,则所有选定的照片和记录应显示在中继器控件中。
我尝试使用查询的存储过程:
select A.*, B.*
from tblStudents A
cross apply
(select top 1 *
from tbl studentImages B
where A.Gender = @Gender and B.ImageID = A.ImageID
但它显示了所有记录,而不是仅显示选定的记录。
任何人都可以帮助吗?
代码背后:
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();
}
}
}
}
您需要在查询中使用加入。
select A.*, B.*
from tblStudents A
join tblstudentImages B on B.ImageID = A.ImageID
where A.Gender = @Gender