hi everyone
can you give an example of coding in vb.net vs2010 how to make a report in crystal report 2013 with sub report
thanks for advanced
hi everyone
can you give an example of coding in vb.net vs2010 how to make a report in crystal report 2013 with sub report
thanks for advanced
@xrjf can you give a link how to display sub report on crystal 2013 step by step in vb.net programming language on vs2010.
best regards
Hi @xrjf
i tried to display crystal report 2013 on vb.net but why the result is empty.
sample program is in the file attachment
thanks for advanced
Dim rpt As New CryRpt_SPK() 'The report
Dim myConnection As SqlConnection
Dim Cmd1 As SqlCommand()
Dim adp1 As SqlDataAdapter()
Dim Cmd2 As SqlCommand()
Dim adp2 As SqlDataAdapter()
Dim ds As New DataSet_MstSPK 'The DataSet master
Dim ds_detspk As New DataSet_DetilSPK 'the dataset sub report
myConnection = New SqlConnection("Data Source=.\SQL2014C;Initial Catalog=TESTDB;Integrated Security = true")
'header on crystal report
ds.SPK.Clear()
ds.GREY.Clear()
ds.DAFTAR_WARNA.Clear()
ds.EnforceConstraints = False
'QUERY FOR MASTER AT CRYSTAL REPORT 2013
cmd1 = New SqlCommand("SELECT NOSPK, TGL_SPK , NAMA_GREY, NAMA_WAR, ROLL_PROD_SPK , KG_PROD_SPK ,KET_SPK " & _
"FROM SPK " & _
"INNER JOIN GREY ON SPK.KODE_GREY = GREY.KODE_GREY " & _
"INNER JOIN DAFTAR_WARNA ON SPK.KODE_WAR =DAFTAR_WARNA .KODE_WAR " & _
"WHERE nospk = '" & Me.txtNoSPK.Text & "' ", myConnection)
adp1 = New SqlDataAdapter(cmd1)
adp1.Fill(ds, "SPK") 'ds --> DataSet_MstSPK
adp1.Fill(ds, "GREY")
adp1.Fill(ds, "DAFTAR_WARNA")
'sub report/detail, crystal report
ds_detspk.DET_SPK.Clear()
ds_detspk.DAFTAR_BENANG.Clear()
ds_detspk.PERSEDIAAN_BENANG.Clear()
ds_detspk.DAFTAR_WARNA.Clear()
ds_detspk.EnforceConstraints = False
cmd2 = New SqlCommand("select DB.NAMA_BRG , DW.NAMA_WAR , ds.BALE_SPK , ds.KG_SPK , ds.KOMPOSISI " & _
"from DET_SPK ds, DAFTAR_BENANG db, PERSEDIAAN_BENANG pb, DAFTAR_WARNA dw " & _
"where DS.KODE_BRG = db.KODE_BRG And ds.KODE_BRG = pb.KODE_BRG " & _
"and ds.KODE_WAR = dw.KODE_WAR and ds.KODE_WAR = pb.KODE_WAR " & _
"and ds.NOSPK = '" & Me.txtNoSPK.Text & "' ", dbCon)
adp2 = New SqlDataAdapter(cmd2)
adp2.Fill(ds_detspk, "DET_SPK") 'ds_detspk ==> DataSet_DetilSPK.xsd
adp2.Fill(ds_detspk, "DAFTAR_BENANG")
adp2.Fill(ds_detspk, "PERSEDIAAN_BENANG")
adp2.Fill(ds_detspk, "DAFTAR_WARNA")
rpt.SetDataSource(ds)
frmViewSPK.CrystalReportViewer1.ReportSource = rpt
frmViewSPK.ShowDialog()
Try:
rpt.SetDataSource(ds.Tables(0))
rpt.Subreports("YourSubreport.rpt").SetDataSource(ds.Tables(1))
I ment:
rpt.SetDataSource(ds.Tables(0))
rpt.Subreports("YourSubreport.rpt").SetDataSource(ds_detspk.Tables(0))
Hi @xrjf
when my program runs on the statement "rpt.SetDataSource(ds.Tables(0))"
there is an error "Column 'KODE_WAR' does not allow nulls."
after I check the DAFTAR_WARNA table or the SPK table, the KODE_WAR field is all filled, there is no Null data.
Query "SELECT NOSPK, TGL_SPK , NAMA_GREY, SPK.KODE_WAR, NAMA_WAR, ROLL_PROD_SPK , KG_PROD_SPK ,KET_SPK
FROM SPK
INNER JOIN GRAY ON SPK.CODE_GREY = GRAY.CODE_GREY
INNER JOIN DAFTAR_WARNA ON SPK.KODE_WAR =DAFTAR_WARNA.KODE_WAR
WHERE nospk = 'PKP-00001' "
I run SQLQuery in SQL Manager, the output record appears.
What is this problem caused by?
thanks for advanced
How many rows are there in ds.Table(0)? What are the fields in each row?
hi xrjf
error problem "Column 'CODE_WAR' does not allow nulls." it's been solved,
it turns out that in the "master dataset" the default KODE_WAR field cannot contain <DBNull>
but there is a new problem with
rpt.Subreports("MySubReport.rpt").SetDataSource(ds_detspk.Tables(0))
new error appears
"Object reference is not set to an instance of an object."
thanks for advanced
Of course, 'MySubReport.rpt' in rpt.Subreports("MySubReport.rpt").SetDataSource(ds_detspk.Tables(0))
should be replaced by the name you have given to your subreport.
'MySubReport.rpt' in rpt.Subreport("MySubReport.rpt").SetDataSource(ds detspk.Tables(0))
is the name of the subreport that I created in the crystal report with the name "CryRpt_SPK.rpt" as defined in
Dim rpt As New CryRpt_SPK() 'The report created.
'Crystal report which contains the master and details which to display the details
'are made in the subreport
Try and verify there are no nulls,
rpt.SetDataSource(ds)
rpt.Subreports("YourSubreport.rpt").SetDataSource(ds_detspk)
Also, there are some answers from some people that had the same problem [Here].(https://stackoverflow.com/questions/7525467/crystal-report-object-reference-not-set-to-an-instance-of-an-object)
Hi @xrjf
apparently the problem is for the error "Object reference not set to an instance of an object." , is caused by the name of the subreport followed by the suffix RPT
The correct writing is as follows:
rpt.Subreports("YourSubreport").SetDataSource(ds_detspk) 'without extension rpt
Thank you for your attention and response
I am happy that you resolved the issue. Regards.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.