Imports
System.Web.UI
Imports
System.Data.SqlClientImports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
dim rpt as new ReportDocument
Private Sub configureCrystalReports() Dim myconnectioninfo As ConnectionInfo = New ConnectionInfo()
myconnectioninfo.DatabaseName =
"test\SqlExpress"
myconnectioninfo.UserID =
"testsa"
myconnectioninfo.Password =
"password"
SetDBLogOnForReport(myconnectioninfo)
End SubPrivate Sub SetDBLogOnForReport(ByVal myConnectionInfo As ConnectionInfo)
Dim myTableLogonInfos As TableLogOnInfos = CrystalReportViewer1.LogOnInfoFor Each myTabeLogoninfo As TableLogOnInfo In myTableLogonInfos
myTabeLogoninfo.ConnectionInfo = myconnectioninfo
Next
End Sub
'------------------------------- Above is for log on info, use the configureCrystalReports() in the click 'event
Private Sub printPayRegister()
Dim thisConnectionString As String = ConfigurationManager.ConnectionStrings("MYConnectionString").ConnectionStringDim myConn As SqlConnection = New SqlConnection(thisConnectionString)Dim MyCommand As New SqlCommand()
MyCommand.Connection = myConn
MyCommand.CommandText =
"SP_PayregisterDetails '" & cmb_Month.SelectedItem.Value + "/" + txt_year.Text & "','" & emp_no & "','" & Department & "', '" & Grade & "'"
MyCommand.CommandType = Data.CommandType.Text
Dim myDa As New SqlDataAdapter
myDa.SelectCommand = MyCommand
Dim myDS As New DS() myDa.Fill(myDS, "SP_PayregisterDetails") 'Stored Procedure
rpt.Load(Server.MapPath(
"PayRegisterA3.rpt"))
rpt.SetDataSource(myDS)
rpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape
Me.CrystalReportViewer1.ReportSource = rpt
End Sub
'--------------------------------------------------------------------------------------------------------------------
'below is the code when u click a button
printPayRegister()
rpt.SetParameterValue("Heading", "Pay Register for the Month of january " ) 'Heading is the parameter name in the report
configureCrystalReports() 'log on info
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath("~/Export/PayRegister.pdf")) exporting this report to pdf
Dim popupscript As String = "<script language='javascript'>" + "window.open('Export/PayRegister.pdf');</script>"
Page.ClientScript.RegisterStartupScript(
Me.GetType(), "PopUpWindow", popupscript, False)
'last two line is a small javascript for poping up the report when the user clicked
hope u got something, by the way i forgot tell u I'm using ASP.Net with VB....