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连接信息