今天又看到初用者不会用水晶报表做动态字段内容,也就是在窗体上输入自己的内容,然后加载到水晶报表中来用 其实很简单,就是传一个参数而已!时间紧迫,先贴上代码,给大家参考,有问题可以发消息给我,以后再写详细点! Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim strGyosya As String Dim Curren As String Dim vendor As String If ComboBox1.SelectedValue = "" And ComboBox1.Text = "" Then MsgBox("请先选择供应商!") Exit Sub End If If ComboBox1.SelectedValue = "" Then strGyosya = ComboBox1.Text Else strGyosya = ComboBox1.SelectedValue End If Dim ss As New System.Text.StringBuilder ss.Append(" SELECT curre,BUMO + ' - ' + NAME AS COMBO FROM XSECT WHERE BUMO='" & strGyosya & "'") Dim Connection1 As New System.Data.SqlClient.SqlConnection(" Data Source=192.168.0.5;Initial Catalog=tpics31;User ID=sa;password=sa") Dim DataAdapter1 As System.Data.SqlClient.SqlDataAdapter Dim DataSet1 As New Data.DataSet Connection1.Open() DataAdapter1 = New System.Data.SqlClient.SqlDataAdapter(ss.ToString, Connection1) DataAdapter1.Fill(DataSet1) Connection1.Close() Curren = DataSet1.Tables(0).Rows(0).Item(0) vendor = DataSet1.Tables(0).Rows(0).Item(1) Dim reportPath As String = Application.StartupPath & "/" & "CrystalReport.rpt" 'Dim reportPath As String = "D:/程式/htk_report/最后版本/MKReport/MKReports/CrystalReport.rpt" Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc.Load(reportPath) 'rptdoc.DataDefinition .FormulaFields () Textbox1 = rptDoc.ReportDefinition.ReportObjects("TxtVendor") Textbox1.Text = vendor Textbox2 = rptDoc.ReportDefinition.ReportObjects("txtcurre") Textbox2.Text = Curren Textbox3 = rptDoc.ReportDefinition.ReportObjects("txttime") Textbox3.Text = Format(DateTimePicker1.Value, "yyyyMMdd") rptDoc.DataDefinition.RecordSelectionFormula = "{XSACT.VENDOR}='" & strGyosya & _ "' AND {XSACT.AKUBU}='" & "K' AND" & _ " {XSACT.IDATE}='" & _ Format(DateTimePicker1.Value, "yyyyMMdd") & "1'" logonInfo.ConnectionInfo.ServerName = "192.168.0.5" logonInfo.ConnectionInfo.DatabaseName = "tpics31" logonInfo.ConnectionInfo.UserID = "sa" logonInfo.ConnectionInfo.Password = "sa" rptDoc.Database.Tables(0).ApplyLogOnInfo(logonInfo) 'rptDoc.DataDefinition.FormulaFields("TxtVendor").Text = vendor 'rptDoc.DataDefinition.FormulaFields("Txtcurre").Text = Curren 'rptDoc.SetDataSource(datatab) rptDoc.Refresh() CrystalReportViewer1.ReportSource = rptDoc CrystalReportViewer1.Refresh() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub