获取不同表中的行数

编程入门 行业动态 更新时间:2024-10-24 00:33:10
本文介绍了获取不同表中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不是查询专家。 i有三个表书,学生,教师。 i想要显示的数量在网页中使用c#asp在单个gridview中的所有这3个表中记录,例如: REPORT no.of books |没有学生|没有教员 100 | 40 | 50 单个表我可以使用查询: select count(bid)from书籍 但是对于3张桌子,我不知道。 如何做到这一点......我可以使用哪些查询?请帮助。

Im not an expert in queries., i have three table "books","students","faculty". i want to display the count of number of records in all these 3 tables in a single gridview using c# asp in a webpage.,like: REPORT no.of books | no.of students | no.of faculty 100 | 40 | 50 for a single table i can use the query: "select count(bid) from books" but for 3 tables,i have no idea., how to do that..what query can i use? pls help.

推荐答案

您可以使用单独的三个查询从数据库中获取数据,也可以创建存储过程以获取单个匹配中的所有计数。以下是可能对您有帮助的代码示例。 You can use separate three queries for fetching data from database or you can create stored procedure to get all counts in a single hit. Below is code sample which may help you. int noOfbooks=0; int noOfStudents=0; int noOffaculty = 0; //Write code here to fetch rows account from database for all three tables. //You can use separate three queries for fetching data from database or you can create //stored procedure to get all counts in a single hit. //After that assign values feteched from database to above variables. DataTable dt = new DataTable(); DataColumn dc = new DataColumn("NoOfBooks"); dt.Columns.Add(dc); dc = new DataColumn("NoOfStudents"); dt.Columns.Add(dc); dc = new DataColumn("NoOfFaculty"); dt.Columns.Add(dc); DataRow dr = dt.NewRow(); dr["NoOfBooks"] = noOfbooks.ToString(); dr["NoOfStudents"] = noOfStudents.ToString(); dr["NoOfFaculty"] = noOffaculty.ToString(); dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind();

更多推荐

获取不同表中的行数

本文发布于:2023-10-19 14:49:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!