Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data.SqlClient
Protected Sub btnCallReport1_Click(sender As Object, e As EventArgs) Handles btnCallReport1.Click
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString, strSQL As String
strConnString = "Server= ของผม ;UID=sa;PASSWORD=xxx;database=xxx;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM vwReport WHERE Date BETWEEN '" & Me.txtDateFrom1.Text & "' AND '" & Me.txtDateTo1.Text & "'"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds, "DataTableReport")
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Dim rpt As New ReportDocument()
''''Dim directory As String = My.Request.Info.DirectoryPath
''''rpt.Load(directory & "\myCrystalReport1.rpt") //ใช้ Mappath แทน
rpt.Load(Server.MapPath("rptShowAllDep.rpt"))
''''rpt.SetDatabaseLogon("UID", "Pass", "Server", "DB") //ลองใส่ก็ไม่ได้***
''''rpt.VerifyDatabase() //ผมลองใส่อันนี้ไม่ได้***
rpt.SetDataSource(dt)
Me.crvReportAllDep.ReportSource = rpt
Me.crvReportAllDep.RefreshReport()
End Sub
Put your report load code in the Page_Init section and use Postback to keep the report in session.
It's prompting because it's loading the report on each page event because it's lost the session.