Home > Database > Mysql Tutorial > Where Should I Put My SQL Query When Integrating It into a Crystal Report in Visual Basic?

Where Should I Put My SQL Query When Integrating It into a Crystal Report in Visual Basic?

Patricia Arquette
Release: 2024-11-19 01:41:02
Original
801 people have browsed it

Where Should I Put My SQL Query When Integrating It into a Crystal Report in Visual Basic?

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
Copy after login

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();
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template