Dim dt As New DataTable
Dim dr As DataRow
'*** Column ***'
dt.Columns.Add("CustomerID")
dt.Columns.Add("Name")
dt.Columns.Add("Email")
dt.Columns.Add("CountryCode")
dt.Columns.Add("Budget")
dt.Columns.Add("Used")
'*** Rows ***'
dr = dt.NewRow
dr("CustomerID") = "C001"
dr("Name") = "Win Weerachai"
dr("Email") = "[email protected]"
dr("CountryCode") = "TH"
dr("Budget") = "1000000"
dr("Used") = "600000"
dt.Rows.Add(dr)
'*** Rows ***'
dr = dt.NewRow
dr("CustomerID") = "C002"
dr("Name") = "John Smith"
dr("Email") = "[email protected]"
dr("CountryCode") = "EN"
dr("Budget") = "2000000"
dr("Used") = "800000"
dt.Rows.Add(dr)
Example
Dim dt As New DataTable
Dim dr As DataRow
'*** Column ***'
dt.Columns.Add("CustomerID")
dt.Columns.Add("Name")
dt.Columns.Add("Email")
dt.Columns.Add("CountryCode")
dt.Columns.Add("Budget")
dt.Columns.Add("Used")
For Each dgv As DataGridViewRow In DataGridView1.Rows
'*** Rows ***'
dr = dt.NewRow
dr("CustomerID") = dgv.Cells(0).Value
dr("Name") = dgv.Cells(1).Value
dr("Email") = dgv.Cells(2).Value
dr("CountryCode") = dgv.Cells(3).Value
dr("Budget") = dgv.Cells(4).Value
dr("Used") = dgv.Cells(5).Value
dt.Rows.Add(dr)
Next
Dim rpt As New ReportDocument()
Dim directory As String = My.Application.Info.DirectoryPath
'rpt.Load(directory & "\myCrystalReport1.rpt")
rpt.Load("C:\DemoCrystalReport2\DemoCrystalReport2\myCrystalReport1.rpt")
rpt.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = rpt
Me.CrystalReportViewer1.Refresh()