Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.net 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.
Posted
Comments
TrushnaK 24-Aug-13 2:13am    
What you think about query which gives you result like this:
Title Counts
no_Of_books 250
no_Of_students 200
no_Of_Faculty 50

1 solution

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();
 
Share this answer
 
Comments
sundaram meenakshi 24-Aug-13 1:43am    
thank you Mahesh Bailwal il try it :)
Mahesh Bailwal 24-Aug-13 1:58am    
you're welcome :) Please mark it solved if it worked for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900