2017-08-15 41 views
0

这是在打印命令 代码与数据库连接成功当我插入域到水晶报表,这就是现场没有出现在报告中的代码

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 
+0

这里有问题吗? –

+0

该字段不会出现在报告中 –

+1

您的SQL返回一个未命名的字段,因为它取决于该函数。您需要使用别名,以便将您的水晶报表所期望的名称作为字段的名称。 –

回答

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

然后对数据集匹配pName字段到晶体报告的字段是Jonathan Willcock说的。

+0

谢谢,它工作正常 –