当我在水晶报表中插入一个字段时,该字段不会出现在报表中

时间:2017-08-15 13:07:51

标签: vb.net crystal-reports

这是print命令的代码 和成功连接数据库的数据集

Try
            Dim rpt As New rptallergy2
            Dim myConnection As SqlConnection
            Dim MyCommand1 As New SqlCommand()
            Dim myDA1 As New SqlDataAdapter()
            Dim myDS As New DataSet
            myConnection = New SqlConnection(cs)

            MyCommand1.Connection = myConnection
            MyCommand1.CommandText = "SELECT RTRIM(patient.name) from patient  "
            MyCommand1.CommandType = CommandType.Text

            myDA1.SelectCommand = MyCommand1

            myDA1.Fill(myDS, "patient")

            rpt.SetDataSource(myDS)
            frmReport.CrystalReportViewer1.ReportSource = rpt
            frmReport.ShowDialog()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

1 个答案:

答案 0 :(得分:1)

MyCommand1.CommandText = "SELECT RTRIM(patient.name) as pName from patient"

然后将pName字段与水晶报告中的字段匹配,这是Jonathan Willcock所说的。