Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have my stored procedure connected to a crystal reports. What i am trying to do is when i highlight a row in datagridview and click report button, only the highlighted row will be displayed in the Crystal report viewer just like shown in the image
Image

Stored procedure code
VB
ALTER PROCEDURE [dbo].[uspLatestDateEnrolled]
    -- Add the parameters for the stored procedure here
@studID INT = NULL

AS
BEGIN

    SET NOCOUNT ON;
SELECT 
            Birthday,getdate() AS [Today],
            Datediff(yy,BirthDay,getdate()) -
            CASE
                WHEN DATEADD(YY, DATEDIFF(YY,BirthDay,getdate()),BirthDay)
                >GETDATE() THEN 1
                ELSE 0

            END AS [age],
        sh.SchoolYear,
        sh.Levels,sh.Section, sh.DateEnrolled ,
        SI.StudentID,SI.Surname,SI.FirstName,SI.MiddleName, SI.StudAddress , 
        SI.BirthDay,SI.Gender, SI.Nationality, SI.BirthPlace,
        SI.TelNum,SI.SchoolWhereGraduated , 
        SI.DatesWhenGraduated, SI.SchoolLastAttended,
        SI.SchoolAddress, SI.Note,SI.StudImage,
        PI.Father_FirstName,PI.Father_LastName,
        PI.Father_MI,PI.Father_Occupation, 
        PI.Father_TelNUm, PI.Mother_FirstName, PI.Mother_LastName,
        PI.Mother_MI,PI.Mother_Occupation,PI.Mother_TelNum,
        PI.Contact_FirstName,PI.Contact_LastName,PI.Contact_MI,
        PI.Contact_Mobile,PI.Contact_TelNum,PI.Contact_Address  
        FROM StudentInformation SI 
        JOIN StudentHistory SH  
            ON SI.StudentID = SH.StudentID
        JOIN ParentInformation PI
        ON PI.ParentID = SI.ParentID
        WHERE si.StudentID = @studID
        ORDER BY DateEnrolled DESC

            SELECT * FROM StudentHistory WHERE StudentID = @studID
                ORDER BY DateEnrolled DESC
            SELECT TOP 1 SchoolYear,
                Levels,Section, DateEnrolled as LatestDate
                FROM StudentHistory
                WHERE studentID = @studID
                ORDER BY DateEnrolled DESC

vb.net code
VB
Private Sub btnRep_Click(sender As Object, e As EventArgs) Handles btnRep.Click
    FrmExampleReport.Show()
    Dim report As New ReportDocument
    report.Load("C:\users\agent_edx44\Documents\Visual studio 2012\projects\SASApp\SASApp\ExampleReport2.rpt")
    report.SetParameterValue("@studID", dgv1.SelectedRows(0).Cells(0).Value)
    frmReport.CrystalReportViewer1.ReportSource = report
    frmReport.CrystalReportViewer1.Refresh()
End Sub


The Problem is that, it does not load the selected records that i choose in the datagridview, it only loads the record that was selected in the crystal reports. Can anyone help me how to solve the issue.Thanks

What I have tried:

I have search solution on google but no luck so i decided to make a thread and i hope anyone could help me to solve the problem.
Posted

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