Search code examples
vb.netcrystal-reports

When I insert a field into crystal report and that's the code the field does not appear in the report


This is the code on the print command and the dataset connected with database successfully

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

Solution

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

    Then match the pName field to the field on your crystal reports is what Jonathan Willcock was saying.