본문으로 바로가기

(vb.net) 데이터셋 크리스탈리포터로 전송

category vb.net 2014. 11. 12. 22:59
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

Dim ds As New DataSet1
        Dim cnn As SqlConnection
        Dim connectionString As String
        Dim sql As String 

        connectionString = "data source=servername; _
initial catalog=crystaldb;user id=username;password=password;"
        cnn = New SqlConnection(connectionString)
        cnn.Open()
sql = "SELECT Product_id,Product_name,Product_price FROM Product"
        Dim dscmd As New SqlDataAdapter(sql, cnn)
        Dim ds As New DataSet1
        dscmd.Fill(ds, "Product")
        MsgBox(ds.Tables(1).Rows.Count)
        cnn.Close()

        Dim objRpt As New CrystalReport1
        objRpt.SetDataSource(ds.Tables(1))
        CrystalReportViewer1.ReportSource = objRpt
        CrystalReportViewer1.Refresh()
    End Sub
End Class