Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am displaying the data from datagrid into crystal report.
For that I have used a data set control,added data table in it & the number of columns in the data set control(same as the number =of columns in datagrid).
Then I am trying to populate that dataset using the below given code but it gives me error "Object reference not set to an instance of an object." I have very little knowledge of crystal report.
My code is
VB
Dim ds As DsRep = New DsRep()
       Dim total As Int16 = frmServerViewReports.DataGridView1.Rows.Count
       Dim i As Int16
       For i = 0 To (total - 1)
           ds.Tables(0).Rows.Add(frmServerViewReports.DataGridView1(0, i).Value.ToString, frmServerViewReports.DataGridView1(1, i).Value.ToString, frmServerViewReports.DataGridView1(2, i).Value.ToString, frmServerViewReports.DataGridView1(3, i).Value.ToString, frmServerViewReports.DataGridView1(4, i).Value.ToString)
       Next


Here DsRep is the name if the dataset control,frmServerViewReport is the name of the form on which the datagrid is placed
Posted
Comments
Toniyo Jackson 5-May-11 2:29am    
Which line you are getting this error?

1 solution

VB
Dim ds As DsRep = New DsRep()
       Dim total As Int16 = frmServerViewReports.DataGridView1.Rows.Count
       Dim i As Int16
       Do Until i = (total - 1)
           Dim a() As String = {frmServerViewReports.DataGridView1(0, i).Value.ToString, frmServerViewReports.DataGridView1(1, i).Value.ToString, frmServerViewReports.DataGridView1(2, i).Value.ToString, frmServerViewReports.DataGridView1(3, i).Value.ToString, frmServerViewReports.DataGridView1(4, i).Value.ToString}
           ds.Tables(0).Rows.Add(a)
           i = i + 1
       Loop
       Dim obj As New crRep
       obj.SetDataSource(ds)
       CrystalReportViewer1.ReportSource = obj


Use this to get the proper output
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900