我正在尝试直接打印我的报告

时间:2018-08-27 12:25:57

标签: vb.net

我正在使用Visual Studio2015。并尝试打印我的报告。我的预览报告工作正常。但是,当我尝试直接打印时,其默认打印的水晶报告。我认为我的功能是错误的。 有人请帮助我。谢谢。

这是我的预览代码(工作正常):

Private Function GetDeliveryChallanPreviewPrint() As DataTable
    Dim Data As New DataTable
    Using conn
        Using cmd As New SqlCommand("select * from DcMaster dm
Left join DcDetail dd on dm.ID = dd.ID where dm.id = '" & PrinByIDTextBox.Text.ToString() & "'", conn)
            conn.Open()
            Using adp As New SqlDataAdapter
                adp.SelectCommand = cmd
                adp.Fill(Data)
                Dim DcPrint As New Rpt_DeliveryChallan
                Dim FILEPATH As String = CurDir() & "\Reports\Rpt_DeliveryChallan.rpt"
                DcPrint.Load(FILEPATH)
                DcPrint.SetDataSource(Data)
                CrystalReportViewer1.ReportSource = DcPrint
                CrystalReportViewer1.Refresh()
                StatusLabel.Visible = False
                conn.Close()
            End Using
        End Using
    End Using
End Function

这是我的直接打印代码:(不起作用)请帮助我。

Private Function GetDeliveryChallanDirectPrint() As DataTable
    Dim Data As New DataTable
    Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("VKDBx").ConnectionString)
        Using cmd As New SqlCommand("select * from DcMaster dm
Left join DcDetail  dd  on dm.ID = dd.ID where dm.id = '" & PrinByIDTextBox.Text.ToString() & "'", conn)
            conn.Open()
            Using adp As New SqlDataAdapter
                adp.SelectCommand = cmd
                adp.Fill(Data)

                Dim DcPrint As New Rpt_DeliveryChallan
                Dim FILEPATH As String = CurDir() & "\Reports\Rpt_DeliveryChallan.rpt"

                DcPrint.PrintOptions.PrinterName = PrinterComboBox.Text
                DcPrint.Load(FILEPATH)
                DcPrint.PrintToPrinter(1, False, 0, 0)
                DcPrint.SetDataSource(Data)
                conn.Close()
            End Using
        End Using
    End Using
End Function

1 个答案:

答案 0 :(得分:0)

我做得很好。 PrintTOPrinter仅向下一行。

Private Function GetDeliveryChallanPrint() As DataTable
    Dim Data As New DataTable
    Using conn As New SqlConnection(_SqlCon)
        Using cmd As New SqlCommand("select * from DcMaster dm
Left join DcDetail  dd  on dm.ID = dd.ID where dm.id = '" & PrintByIDLabel.Text.ToString() & "'", conn)
            conn.Open()
            Using adp As New SqlDataAdapter
                adp.SelectCommand = cmd
                adp.Fill(Data)

                Dim Printrpt As New Rpt_DeliveryChallan
                Dim FILEPATH As String = CurDir() & "\Reports\Rpt_DeliveryChallan.rpt"

                Printrpt.PrintOptions.PrinterName = PrinterComboBox.Text
                Printrpt.Load(FILEPATH)
                Printrpt.SetDataSource(Data)
                Printrpt.PrintToPrinter(NumberOfCopiesNumericUpDown.Value, False, 0, 0)

            End Using
        End Using
    End Using
End Function