Issue: Integrating Query into Report
When designing a Crystal Report using Visual Basic, finding the correct location to input your SQL query may be puzzling. Let's unravel the solution.
In the Crystal Report wizard, locate the ODBC connection you've established with the appropriate username and password.
Upon locating the ODBC connection, you will notice a "Command text" field. This is where you can place your SQL query. It will allow the report to access the necessary data from your database.
Sample Code:
For VB.NET:
Private CRPT As New ReportDocument Private APPPATH As String Private PARAM As New ParameterFields Public PARAM_DESC As New ParameterDiscreteValue Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load APPPATH = Application.StartupPath & "\REPORT\sample.rpt" CRPT.Load(APPPATH) Me.CrystalReportViewer1.ReportSource = CRPT PARAM = CRPT.ParameterFields PARAM_DESC.Value = Format(DatePicker1.Value, "yyyyMMdd") PARAM("DATEP").CurrentValues.Clear() PARAM("DATEP").CurrentValues.Add(PARAM_DESC) Me.CrystalReportViewer1.Refresh() End Sub
For C#:
CRPT = new ReportDocument(); APPPATH = Environment.CurrentDirectory + "Sample.rpt"; CRPT.Load(APPPATH); Report_Viewer.Refresh(); CRPT.SetParameterValue("syear", Servercls.year); CRPT.SetParameterValue("smonth", Servercls.month); CRPT.SetParameterValue("sday", Servercls.day); CRPT.SetParameterValue("datevalue", Servercls.Datevalue); Report_Viewer.ReportSource = CRPT; sc.configureCrystalReport(); Report_Viewer.Refresh();
Note that the Crystal Report parameter names must align with the parameter names in your code-behind. This integration ensures that your report displays the correct data based on the query parameters you've defined.
The above is the detailed content of Where Should I Put My SQL Query When Integrating It into a Crystal Report in Visual Basic?. For more information, please follow other related articles on the PHP Chinese website!