标签:new public bsp .config orm vat rom private ado
沒有出現CrystalReportViewer時,須安裝CRforVS_13_0.
新增1個數據集,新增1個數據表,添加二列,列名要和資料庫名一樣.
修改目標Framework
修改app.config,
<startup >改成<startup useLegacyV2RuntimeActivationPolicy ="true">
CrystalReport1.rpt增加數據庫專家
在表單上放入一個CrystalReportViewer1和一個按鈕
程式如下:
Imports CrystalDecisions.Windows.Forms
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data.SqlClient ‘ADO連線
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New SqlConnection("Password=密碼;Persist Security Info=True;User ID=帳號;Initial Catalog=資料庫;Data Source=連線位置")
Dim cmd As New SqlCommand("SELECT BADGENUMBER, NAME FROM USERINFO", cn)‘sql語言
Dim da As New SqlDataAdapter
Dim ds As New DataSet
da.SelectCommand = cmd
da.Fill(ds, "DataTable1")‘新增的數據集DataSet1.xsd,的數據表DataTable1
Dim doc As New ReportDocument
doc.Load("C:\VB\CrystalReport1.rpt")‘CrystalReport1.rpt所在位置不能是中文
doc.SetDataSource(ds)
CrystalReportViewer1.ReportSource = doc
End Sub
End Class
運行畫面如下
vb.net 水晶報表CrystalReport 動態設定資料庫來源
标签:new public bsp .config orm vat rom private ado
原文地址:https://www.cnblogs.com/leme-chen/p/9924560.html