簡體   English   中英

如何在datagridview中顯示選定的行以水晶報表

[英]How to display selected rows in datagridview to crystal report

這是我第一次使用Crystal Reports。我有一個存儲過程,我想做的是當我在datagridview突出顯示一行並單擊report按鈕時,只有突出顯示的行才被發送到Report Viewer頁面。一些解決方案,但沒有運氣。

報告按鈕代碼

Imports System.Data.SqlClient
Imports System.IO
Imports CrystalDecisions.CrystalReports.Engine

Public Class frmView
    Dim cn As New SqlConnection("Data Source=.;Initial Catalog=DBSAS;Integrated Security=True")
    Dim cmd As New SqlCommand
    Dim da As New SqlDataAdapter
    Dim dt As New DataTable
    Dim i As Integer
    Dim a As New OpenFileDialog

    Private Sub btnRep_Click(sender As Object, e As EventArgs) Handles btnRep.Click 
            cn.Open()
        Dim report As New ReportDocument
        da.SelectCommand = New SqlCommand("EXEC usplatestDateEnrolled ", cn)
        report.RecordSelectionFormula = "{@studID}" & dgv1.SelectedRows(0).Cells(0).Value
        report.Load("C:\users\agent_edx44\My Documents\Visual studio 2012\projects\SASApp\Rep.rpt")
        frmReport.CrystalReportViewer1.ReportSource = report
        frmReport.CrystalReportViewer1.Refresh()
        frmReport.Show()
            cn.Close()
    End Sub

End Class

存儲過程代碼

USE [DbSAS]
GO
/****** Object:  StoredProcedure [dbo].[uspLatestDateEnrolled]    Script Date: 02/07/2016 12:35:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[uspLatestDateEnrolled]
    -- Add the parameters for the stored procedure here

@studID INT = NULL


AS
BEGIN

    SET NOCOUNT ON;
SELECT 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

當我運行此代碼時,它說

此行中的報告文件路徑無效

report.RecordSelectionFormula = "{@studID}" & dgv1.SelectedRows(0).Cells(0).Value

誰能幫我修復我的代碼。 我被困在這里將近一個小時。 提前致謝

嘗試在此行的末尾添加.ToString:

report.RecordSelectionFormula = "{@studID}" & dgv1.SelectedRows(0).Cells(0).Value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM