3个回答
展开全部
首先引用Crystal Reports 9 ActiveX Designer Run Time Library
再添加Crystal Repotr View Control 9控件
在工程资源管理器中右键--添加--Crystal Reports 9 新建一个Crystal Reports9报表
设置数据源后将要显示的字段加入报表内。
窗体代码部分:
Dim m_Report As New CrystalReport1 \'(这个CrystalReport1是你建立的报表的名称)
Dim m_Connection As ADODB.Connection \'(建立一个ADO连接)
Dim adoRS As ADODB.Recordset
Private Sub Form_Load()
Dim SQL As String
Dim strConnect As String
\' Create and bind the ADO Recordset object
Set m_Connection = New ADODB.Connection
Set adoRS = New ADODB.Recordset
\' Open the connection
strConnect = "你的数据库连接字符串"
m_Connection.Open strConnect
SQL = "查询语句"
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic
m_Report.Database.SetDataSource adoRS\'(动态设置报表数据源)
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport \'(显示报表)
Screen.MousePointer = vbDefault
End Sub
此代码在VB6+SP5+Windows2000 Server下调试通过
以上代码参考水晶报表9中文版
再添加Crystal Repotr View Control 9控件
在工程资源管理器中右键--添加--Crystal Reports 9 新建一个Crystal Reports9报表
设置数据源后将要显示的字段加入报表内。
窗体代码部分:
Dim m_Report As New CrystalReport1 \'(这个CrystalReport1是你建立的报表的名称)
Dim m_Connection As ADODB.Connection \'(建立一个ADO连接)
Dim adoRS As ADODB.Recordset
Private Sub Form_Load()
Dim SQL As String
Dim strConnect As String
\' Create and bind the ADO Recordset object
Set m_Connection = New ADODB.Connection
Set adoRS = New ADODB.Recordset
\' Open the connection
strConnect = "你的数据库连接字符串"
m_Connection.Open strConnect
SQL = "查询语句"
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic
m_Report.Database.SetDataSource adoRS\'(动态设置报表数据源)
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport \'(显示报表)
Screen.MousePointer = vbDefault
End Sub
此代码在VB6+SP5+Windows2000 Server下调试通过
以上代码参考水晶报表9中文版
展开全部
首先引用Crystal Reports 9 ActiveX Designer Run Time Library
再添加Crystal Repotr View Control 9控件
在工程资源管理器中右键--添加--Crystal Reports 9 新建一个Crystal Reports9报表
设置数据源后将要显示的字段加入报表内。
窗体代码部分:
Dim m_Report As New CrystalReport1 \'(这个CrystalReport1是你建立的报表的名称)
Dim m_Connection As ADODB.Connection \'(建立一个ADO连接)
Dim adoRS As ADODB.Recordset
Private Sub Form_Load()
Dim SQL As String
Dim strConnect As String
\' Create and bind the ADO Recordset object
Set m_Connection = New ADODB.Connection
Set adoRS = New ADODB.Recordset
\' Open the connection
strConnect = "你的数据库连接字符串"
m_Connection.Open strConnect
SQL = "查询语句"
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic
m_Report.Database.SetDataSource adoRS\'(动态设置报表数据源)
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport \'(显示报表)
Screen.MousePointer = vbDefault
End Sub
此代码在VB6+SP5+Windows2000 Server下调试通过
以上代码参考水晶报表9中文版
再添加Crystal Repotr View Control 9控件
在工程资源管理器中右键--添加--Crystal Reports 9 新建一个Crystal Reports9报表
设置数据源后将要显示的字段加入报表内。
窗体代码部分:
Dim m_Report As New CrystalReport1 \'(这个CrystalReport1是你建立的报表的名称)
Dim m_Connection As ADODB.Connection \'(建立一个ADO连接)
Dim adoRS As ADODB.Recordset
Private Sub Form_Load()
Dim SQL As String
Dim strConnect As String
\' Create and bind the ADO Recordset object
Set m_Connection = New ADODB.Connection
Set adoRS = New ADODB.Recordset
\' Open the connection
strConnect = "你的数据库连接字符串"
m_Connection.Open strConnect
SQL = "查询语句"
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic
m_Report.Database.SetDataSource adoRS\'(动态设置报表数据源)
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport \'(显示报表)
Screen.MousePointer = vbDefault
End Sub
此代码在VB6+SP5+Windows2000 Server下调试通过
以上代码参考水晶报表9中文版
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
vb做报表很麻烦 如果表格复杂可以考虑用水晶报表
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询