查询 Crystal Reports 中的两个表
要在 Crystal Reports 中使用自定义查询,请导航到在数据库专家工具中创建的 ODBC 连接。找到“命令文本”字段并输入 SQL 查询。
所提供查询的语法如下:
SELECT ts.`SCHEDIDNO`, ts.`DAYNAME`, DATE_FORMAT(ts.`TIMESTART`, '%h:%i %p') as TIMESTART, DATE_FORMAT(ts.`TIMEEND`, '%h:%i %p') as TIMEEND, ts.`GRADELEVEL`, ts.`SECTIONNAME`, ts.`SUBJECTNAME`, ts.`FACFULLNAME`, ts.`ROOMNAME`, tf.`FACFULLNAME` as PERSONNEL, tf.`DEPARTMENT`, tse.`Adviser` FROM `tblschedule` ts, `tblfaculty` tf, `tblsection` tse WHERE ts.`GRADELEVEL` = " & lblgrade.Text & " AND ts.`SECTIONNAME` = '" & lblsect.Text & "' AND ts.`DEPARTMENTNAME` = tf.`DEPARTMENT` AND tf.`ADMINISTRATOR` = 1 AND tse.`SECTIONNAME` = '" & lblsect.Text & "'
在 Visual Basic.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
在 C# 中,使用以下命令code:
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();
请记住确保水晶报表中的参数名称与后面代码中的参数名称相匹配。
以上是如何使用VB.NET和C#查询水晶报表中的两个表?的详细内容。更多信息请关注PHP中文网其他相关文章!