本文介绍了获取不同表中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不是查询专家。 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();
更多推荐
获取不同表中的行数
发布评论