locked
Crystal report view problem RRS feed

  • Question

  • i'm using visual studio 2012 and Microsoft SQL server 2012 to make a program.

    this is my windows for for print report on crystal report:


    this is the code in the windows form:

    Imports System.Data.SqlClient
    Public Class FormLihatLaporan
    
        Private Sub FormLihatLaporan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            DataGridView1.AllowUserToAddRows = False 'hilangkan bintang SQL'
            ClassKoneksi.namadatabase = "KPIRWAN"
            ClassSiswa.namadatabase = "KPIRWAN"
    
            datagridview()
            Dim dssiswa As New DataSet
            Dim sql As String
            sql = "select*from siswa order by nis ASC"
            dssiswa = ClassSiswa.displayData(ClassSiswa.opencon, sql, "DataSiswa")
            DataGridView1.DataSource = dssiswa
            DataGridView1.DataMember = "DataSiswa"
            DataGridView1.ReadOnly = True
            ClassSiswa.closecon()
        End Sub
        Sub datagridview()
            Dim sql As String
            Dim dsdata As New DataSet
            sql = "select*from siswa"
            dsdata = ClassSiswa.displayData(ClassSiswa.opencon, sql, "siswa")
            DataGridView1.DataSource = dsdata
            DataGridView1.DataMember = "siswa"
            DataGridView1.ReadOnly = True
            ClassSiswa.closecon()
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim dssiswa As New DataSet
            Dim sql As String
            sql = "select*from Siswa where NIS ='" & TextBox1.Text & "'"
            dssiswa = ClassSiswa.displayData(ClassSiswa.opencon, sql, "DataSiswa")
            DataGridView1.DataSource = dssiswa
            DataGridView1.DataMember = "DataSiswa"
            DataGridView1.ReadOnly = True
            ClassSiswa.closecon()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim dssiswa As New DataSet
            Dim sql As String
            sql = "select*from Siswa where Nama_Siswa like '%" & TextBox2.Text & "%'"
            dssiswa = ClassSiswa.displayData(ClassSiswa.opencon, sql, "DataSiswa")
            DataGridView1.DataSource = dssiswa
            DataGridView1.DataMember = "DataSiswa"
            DataGridView1.ReadOnly = True
            ClassSiswa.closecon()
        End Sub
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Print.Click
            If Len(Trim(TextBox1.Text)) = 0 Then
                MsgBox("Masukan Nis Terlebih Dahulu")
                TextBox1.Focus()
                Exit Sub
            End If
            Dim dssiswa As New DataSet
            Dim sql As String
            sql = "select*from Siswa where Nis like '%" & TextBox1.Text & "%'"
            dssiswa = ClassSiswa.displayData(ClassSiswa.opencon, sql, "DataSiswa")
    
            Dim tampil As New FrmViewer
            Dim cetak As New RptSiswa
    
            cetak.SetDataSource(dssiswa.Tables("DataSiswa"))
            tampil.CrystalReportViewer1.ReportSource = cetak
            tampil.WindowState = FormWindowState.Maximized
            tampil.Refresh()
            tampil.Show()
        End Sub
        Private Sub btntutup_Click(sender As Object, e As EventArgs) Handles btntutup.Click
            Me.Close()
        End Sub
    End Class

    Button 1 for search based on Nis.

    Button 2 for search based on Name.

    Button 3 for print in crystal report.

    in the datagridview there is 5 row of table, what i want is to print only the data i search with button 1 or 2  into the crystal report.

    for example: if i search the name andi and click button 2 (search) then, the datagridview only show one row with the name andi. then, after i click button 3 (print) the crystal report will only show me the report about andi.

    the problem is:

    after i search the name using button 2(search) and clicked button 3 (print), the crystal report showed me all the data recorded on the datagridview.

    how do i make a coding to only print the crystal report based on the category that i searched?


    • Edited by cxsfgfhtutu Wednesday, June 10, 2015 10:05 AM
    • Moved by Youjun Tang Thursday, June 11, 2015 3:19 AM Not supported
    Wednesday, June 10, 2015 8:23 AM

Answers