查詢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# 中,使用以下程式碼:
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();
請記得確保Crystal Report中的參數名稱與程式碼中的參數名稱相符後面。
以上是如何使用VB.NET和C#查詢水晶報表中的兩個表格?的詳細內容。更多資訊請關注PHP中文網其他相關文章!