简体   繁体   English

如何从SQL Server数据库表列中获取Male或Female并在转发器控件中显示记录?

[英]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.

相关问题 如何从 model 创建包含男性和女性的列表以查看 - How to create a list with Male and Female from model to view 如何在C#中创建动态服务器控件,以及如何将更多记录从数据库追加到转发器控件,而无需再次加载全部 - How to create dynamic server controls in C# and how to append more records from the database to repeater control without loading all once again 如何从SQL Server将图像加载到转发器控件中? - How to load image into a repeater control from sql server? 如何将所有记录从SQL SERVER数据库表保存到数组中? - How to save all records into an array from the SQL SERVER database table? 无法在GridView中显示性别的男性/女性 - Can't display male/female for gender in gridview 如何从SQL数据库中的表中一个接一个地获取下一条记录 - How to fetch the next records from a table in sql database one after other 计算“男性”和“女性”在访问数据库(asp.net,C#)的字段中出现多少次 - Count how many times 'male' and 'female' appears in a field in access database (asp.net, C#) 在 C# 列表框或文本框中显示来自 SQL 服务器数据库表的日期列值 - Display Date Column values from a SQL Server database table in a C# listbox or textbox 使用转发器控制从SQL数据库中进行下拉列表搜索 - Dropdown List Search From SQL Database Using Repeater Control 如何通过linq查询在datagridview控件上仅显示SQL Server数据库数据的选定字段(从复选框)? - How to display only selected fields (from checkboxes) of a SQL Server database data on a datagridview control through linq query?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM