net制作水晶報表分以下
個步驟
新建一個windows applicationCristalTest;
新添加一個數據集DataSetxsd
在DataSet裡添加表DataTable
在DataTable裡添加四列ColumnColumnColumnColumn 保存
添加一個水晶報表文件CrystalReportrpt
設置數據源項目數據(Project Data)>Adonet DataSets>***DataSet>DataTable
把ColumnColumnColumnColumn拖到水晶報表的細節(Details)中
添加一個控件CrystalReportViewer到Form中
然後添加Form_Load的代碼
Dim m_sqlConn As SqlConnection
Dim m_strSqlConn As String
m_strSqlConn = Data Source=localhost; initial catalog=pubs;User id=sa;password=
m_sqlConn = New SqlConnection(m_strSqlConn)
Try
Dim sqlAdp As SqlDataAdapter
Dim strSql As String
Dim ds = New DataSet()
m_sqlConnOpen()
strSql = SELECT au_lname AS Column au_fname AS Column phone AS Column address AS Column FROM dboauthors
sqlAdp = New SqlDataAdapter(strSql m_sqlConn)
sqlAdpFill(ds)
Dim crReportDocument = New CrystalReport()
crReportDocumentSetDataSource(dsTables())
CrystalReportViewerReportSource = crReportDocument
Catch ex As Exception
MessageBoxShow(exToString())
End Try
在formvb文件頭加
Imports SystemData
Imports SystemDataSqlClient
m_strSqlConn = Data Source=localhost; initial catalog=pubs;User id=sa;password=這個可能要修改成你的機器的Sql Server連接信息
From:http://tw.wingwit.com/Article/program/net/201311/15804.html