i am working on windows Form application and wanted to perform Paging in DataGridView
so i wrote a query for that
Select DISTINCT TOP(1000)
TblStudentBioData.RegNo
, Coalesce(TblStudentBioData.First_NameUr + SPACE(1) +
TblStudentBioData.Middle_NameUr + SPACE(1),TblStudentBioData.First_NameUr)
+ TblStudentBioData.Last_NameUr AS Name
, TblStudentBioData.Father_NameUr
, Coalesce(Ay.AcademicYearName,N'+@InCaseNull+') As AcademicYearName
, Coalesce(Smst.SemName,N'+@InCaseNull+') As SemName
, Coalesce(Colg.CollegeName,N'+@InCaseNull+') As CollegeName
, Coalesce(CID.ClassName,N'+@InCaseNull+') As ClassName
, TblImages.Images
, TblStudentBioData.Student_ID
, TblImages.ImageId
, Ay.AcademicYearId
, Smst.SemesterId
, TblClassSchedule.ClassSchId
FROM TblStudentBioData
INNER JOIN TBLCFGSEX AS sex
ON TblStudentBioData.CfgSexId = sex.CfgSexId
LEFT JOIN TBLMARITALSTATUS ms
ON TblStudentBioData.MaritalStatusId = ms.MaritalStatusId
INNER JOIN TblImages
ON TblStudentBioData.ImageId = TblImages.ImageId
LEFT JOIN TBLBLOODGROUP BG
ON TblStudentBioData.BloodID = BG.BloodId
LEFT JOIN TblStudentDetail
ON (TblStudentBioData.Student_ID = TblStudentDetail.Student_ID)
LEFT JOIN TblStudentSubAss
ON TblStudentDetail.StudentDetailID = TblStudentSubAss.StudentDetailID
LEFT JOIN TblClassSchedule
ON TblStudentDetail.CLassSchID = TblClassSchedule.ClassSchID
LEFT JOIN TblSubAss
ON TblSubAss.SubAssId = TblStudentSubAss.SubAssId
LEFT JOIN TblClass AS CID
ON TblClassSchedule.ClassID = CID.ClassID
LEFT JOIN TBLCOLLEGE Colg
ON CID.CollegeId = Colg.CollegeID
LEFT JOIN TblSemAssigning SA
ON TblClassSchedule.SemAssId = SA.SemAssId
LEFT JOIN TblAcademicYear AY
ON SA.AcademicYearId = AY.AcademicYearId
LEFT JOIN TblSemester Smst
ON Smst.SemesterId = SA.SemesterId
This Query Return me more than 28K
rows but for paging i want only 1000 rows and total records which is 28K
i will be fetching records 1000
wise.
Any Idea how can i do this ?
Note:
This query takes more then 20 seconds to execute and i wanted a solution which does not increase executing time.