title: Export datatable to crystal report
body: <p>I created a datatable (.xsd) that corresponds to the datatable I coded in the code-behind.</p>
  
  <p><img src="https://i.stack.imgur.com/qQhUi.jpg" alt="Figure 1"></p>
  
  <pre><code>Protected Sub btnDproceed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDproceed.Click
  
  
      '---&gt; ASSUME THAT I CODES FOR THE FIRST FOUR COLUMNS OF DATATABLE IS MADE HERE
      '---&gt; CREATE DYNAMIC COLUMNS OF SCORES
      cn.Open()
      '---&gt; SQL COMMAND HERE THAT GET TOP 5 DATA FROM DATABASE USED TO GENERATE 5 ADDITIONAL COLUMNS IN dt
      rs = cmd.ExecuteReader
      Do While rs.Read
          Dim gwno As String = rs.Item("GWNO").ToString
          If gwno.Length = 1 Then
              gwno = "0" &amp; gwno
          End If
          Dim vHeader As String = "LES" &amp; gwno &amp; "_" &amp; rs.Item("GWTYPE")
          If Not dt.Columns.Contains(vHeader) Then
              Dim f As New Data.DataColumn(vHeader, GetType(System.String))
              dt.Columns.Add(f)
              f.AllowDBNull = True
          End If
      Loop
      cn.Close()
  
      '---&gt; DATA ROWS FOR SCORES
      For Each row As DataRow In dt.Rows
          If Not dt.Columns.Contains("RANK") Then
              dt.Columns.Add("RANK").SetOrdinal(0)
          End If
          Dim v As Integer
          v = v + 1
          row(0) = v.ToString
          For col As Integer = 4 To dt.Columns.Count - 1
              '---&gt; SQL COMMAND THAT GETS DATA (score) BASED ON THE 5 GENERATED COLUMNS ABOVE
              rs = cmd.ExecuteReader
              If rs.Read = True Then
                  If Not String.IsNullOrEmpty(rs.Item("SCORE").ToString) Then
                      row(col) = rs.Item("SCORE").ToString
                  Else
                      row(col) = rs.Item("REMTYPE").ToString
                  End If
              End If
              cn.Close()
          Next
      Next
  
      '---&gt; ADDITIONAL STATIC COLUMNS
      dt.Columns.Add("LE_SUM")
      dt.Columns.Add("LE_CNT")
      dt.Columns.Add("LE_AVE")
      dt.Columns.Add("UE_SUM")
      dt.Columns.Add("UE_CNT")
      dt.Columns.Add("UE_AVE")
      dt.Columns.Add("AVERAGE")
      dt.Columns.Add("CGRADE")
      dt.Columns.Add("+/-GPTS")
      dt.Columns.Add("CRANK")
      dt.Columns.Add("DEF")
      dt.Columns.Add("EXPTD")
      dt.Columns.Add("ABCNT")
      dt.Columns.Add("INC")
  
      Dim crpt As New ReportDocument()
      CrystalReportViewer1.DisplayGroupTree = False
      crpt.Load(Server.MapPath("~/CrystalReport.rpt"))
      crpt.SetDataSource(dt)
      CrystalReportViewer1.ReportSource = crpt
  End Sub
  </code></pre>
  
  <p>As seen above, the <code>dt</code> and <code>Scores.xsd</code> has similar datacolumns which will be used in generating the crystal report (yes, it's working). But the problems are the Top 5 columns and it's corresponding data. In <code>Scores.xsd</code>, <code>DataColumn5</code> to <code>DataColumn9</code> and <code>DataColumn24</code> to <code>DataColumn28</code> can't generate data in Crystal Report since in <code>datatable dt</code>, there's no same name datacolumns. Now, how can I make there columns in Crystal Report since these columns are changing depending on the <code>Top 5</code>.</p>