VB.NET MySQL在多列中显示单列数据

时间:2016-01-06 19:43:22

标签: mysql vb.net crystal-reports

我有一个MySQL表,如下所示......

----------------------------------------------------------
| id | student_id |  amount  |    date    |    purpose   |
----------------------------------------------------------
| 1  |    1       |  3000.00 | 01/01/2016 | Admission    |
| 2  |    1       |   600.00 | 05/01/2016 | 1st Inst.    |
| 3  |    1       |   600.00 | 06/01/2016 | 2nd Inst.    |
----------------------------------------------------------

现在我想在下面展示它(在水晶报告中)......

-------------------------------------------------------------
| student_id | Admission | 1st Inst. | 2nd Inst. | tot_paid |
-------------------------------------------------------------
|    1       |   3000.00 | 600.00    | 600.00    | 4200.00  |
-------------------------------------------------------------

我的代码是......

Dim st_id As String = String.Empty
Dim adm As Integer = 0
Dim fst As Integer = 0
 Dim scnd As Integer = 0
 Dim total_paid As Integer = 0

 OpenConnection()
 Dim dbcommand As New MySqlCommand
 Dim dbadapter As New MySqlDataAdapter
 Dim dt As New DataTable
 dt.Columns.Add("st_id")
 dt.Columns.Add("admission", GetType(Integer))
 dt.Columns.Add("first", GetType(Integer))
 dt.Columns.Add("second", GetType(Integer))
 dt.Columns.Add("total_paid", GetType(Integer))

 Dim qry As String = "Select " & _
 "fee_payment.st_id AS st_id," & _
 "fee_payment.amt AS amt," & _
 "fee_payment.purpose AS purpose," & _
 "From " & _
 "fee_payment Inner Join " & _
 "master_student On master_student.st_id = fee_payment.st_id WHERE course='" & course & "' GROUP BY st_id"
 dbcommand.Connection = conn
 dbcommand.CommandText = qry
 Dim dr As MySqlDataReader = dbcommand.ExecuteReader
 While dr.Read
      Dim st_id= dr("st_id")
      Dim amt = dr("amt")
      Dim purpose = dr("purpose")

      If purpose = "ADMISSION" Then
                adm = amt
            Else
                adm = 0
            End If
            If purpose = "1st Inst." Then
                fst = amt
            Else
                fst = 0
            End If

            If purpose = "2nd Inst." Then
                scnd = amt
            Else
                scnd = 0
            End If

            total_paid = adm + fst + scnd

            Dim R As DataRow = dt.NewRow
            R("st_id") = st_id
            R("admission") = adm
            R("first") = fst
            R("second") = scnd
            R("total_paid") = total_paid
            dt.Rows.Add(R)
        End While
        dr.Close()


        Dim stdata As New DataSet()
        stdata.Tables.Add(dt)
        stdata.WriteXml(Application.StartupPath & "\ReportXml\duelist.xml", XmlWriteMode.WriteSchema)

在生成报告时,它仅显示第一条记录,即Admission目的。没有显示其他记录。

我该怎么办?

0 个答案:

没有答案