'采用 Grid++Report5 破解版
'[工程]--[引用] C:\Grid++Report 5.0\gregn50.dll
Public SQL2008 As String
Public gblServer As String
Public gblDataBase As String
Public gblServerLogID As String
Public gblServerPwd As String
Public gblRemoteServerIP As String '远程服务器地址
Public Sub 获取数据库连接字符串() '下面配置需要修改下
gblServerLogID = "sa" 'SQL2008数据库账号
gblServerPwd = "111222" 'SQL2008数据库密码
gblDataBase = "BoYa" '数据库名称
gblServer = "127.0.0.1,1433" ' SQL2008所在的电脑IP地址,还要打开本地端口1433
SQL2008 = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & gblServerLogID & _
";pwd=" & gblServerPwd & _
";Initial Catalog=" & gblDataBase & _
";Data Source=" & gblServer
获取数据库连接字符串 = SQL2008
End Sub
'返回报表连接字符串
'设置打印属性
Public Sub ReportDtl(ReportTemplate As String, SQL As String, filename As String, PrintDirect As Boolean)
On Error GoTo Err
Dim Report As New grproLib.GridppReport
Report.LoadFromFile (App.Path & "\报表\" & ReportTemplate) '报表文件目录
初始化数据库连接字符串
'设置数据库连接
Report.DetailGrid.Recordset.ConnectionString = 获取数据库连接字符串() '数据库连接字符串
'设置数据源
Report.DetailGrid.Recordset.QuerySQL = SQL
'设置导出文件名
Report.Title = filename
'显示
If PrintDirect Then
Report.PrintEx grpgsAll, False
Else
Report.PrintPreview (True)
End If
Exit Sub
Err:
MsgBox Err.Description, vbCritical, "错误"
End Sub
Public Sub 打印销售清单()
Dim rptSQL As String
rptSQL = "Select * from 销售清单表 where 销售单号='001'" 'SQL语句需要修改下
ReportDtl "销售单.grf", rptSQL, "销售单", False
End Sub
代码如上,把以上代码放到 VB的模块里面即可。
qq1016058890
源码和打印模块 链接: https://pan.baidu.com/s/144u_ywG_vMpHlqmV2zkDKA 提取码: qrsq