我在使用左连接在水晶报表中显示数据时遇到问题,因为它复制了我的数据,即使我在sqlcommand中使用GROUP BY。
这是我的表格列表:
table 1: complaint
table 2: errordesc (error description)
这是我在水晶报告中的代码:
Dim objConn As MySqlConnection
Dim daT1, daT2 As MySqlDataAdapter
Dim activecomp As DataSet
Dim strConnection As String
Dim strSQL As String
strConnection = "server=localhost;user id=root;password=;database=ticketing_system;"
objConn = New MySqlConnection(strConnection)
objConn.Open()
strSQL = "SELECT * FROM errordesc LEFT JOIN complaint ON errordesc.tran_no=complaint.tran_no WHERE errordesc.status='On-process' group by errordesc.err_id "
daT1 = New MySqlDataAdapter(strSQL, objConn)
activecomp = New DataSet
daT1.Fill(activecomp, "comp")
daT1.Fill(activecomp, "active")
Dim rpt As New CrystalReport1
rpt.SetDataSource(activecomp)
CrystalReportViewer1.ReportSource = rpt
objConn.Close()
我的出局是这样的:
它重复了我的errordesc.err_id,即使我把它归为一组。 :(请帮助,如果有人知道。提前谢谢......
答案 0 :(得分:1)
我认为删除重复行的简单方法是更改strSQL
:
strSQL = "SELECT DISTINCT * FROM errordesc LEFT JOIN "+
"complaint ON errordesc.tran_no=complaint.tran_no "+
"WHERE errordesc.status='On-process' group by errordesc.err_id "
答案 1 :(得分:0)
oohh。我通过编写像这样的水晶报告解决了我自己的问题:
Dim objConn As MySqlConnection
Dim daT1, daT2 As MySqlDataAdapter
Dim activecomp As DataSet
Dim strConnection As String
Dim strSQL As String
strConnection = "server=localhost;user id=root;password=;database=ticketing_system;"
objConn = New MySqlConnection(strConnection)
objConn.Open()
strSQL = "SELECT * FROM errordesc WHERE errordesc.status='On-process' group by errordesc.err_id "
daT1 = New MySqlDataAdapter(strSQL, objConn)
activecomp = New DataSet
daT1.Fill(activecomp, "errordesc")
strSQL = "SELECT * FROM complaint left join errordesc on complaint.tran_no=errordesc.tran_no group by complaint.tran_no"
daT2 = New MySqlDataAdapter(strSQL, objConn)
daT2.Fill(activecomp, "complaint")
Dim rpt As New CrystalReport1
rpt.SetDataSource(activecomp)
CrystalReportViewer1.ReportSource = rpt
objConn.Close()