我的代码是:
dim rs as new adodb.re...
dim con as new ......
dim rtp as new datareport1
dim sql as string
sql="select * from temp1"
con.open "shcq" \\\\shcq是建的ODBC
set rs=con.execute(sql)
rtp.datasource=rs
rtp.show
为什么在rtp中什么东西也显示不出来。是还要做什么吗。给点意见或代码!
dim rs as new adodb.re...
dim con as new ......
dim rtp as new datareport1
dim sql as string
sql="select * from temp1"
con.open "shcq" \\\\shcq是建的ODBC
set rs=con.execute(sql)
rtp.datasource=rs
rtp.show
为什么在rtp中什么东西也显示不出来。是还要做什么吗。给点意见或代码!
rtp.show改成:
set rtp.datasource=rs
rtp.show
rtp.show
上面写的时候写错呢
On Error Resume Next
DoEvents
If DE1.Connection1.State = 0 Then DE1.Connection1.Open
rptGetMon.Sections.Item("Reportheader").Controls.Item("khname").Caption = Combo1.Text
rptGetMon.Sections.Item("Reportheader").Controls.Item("rq").Caption = txt_Date1.Text & "---" & txt_Date2.Text
rptGetMon.Sections.Item("Reportheader").Controls.Item("hhj").Caption = hhj.Text
rptGetMon.Sections.Item("Reportheader").Controls.Item("chj").Caption = chj.Text
rptGetMon.Sections.Item("Reportheader").Controls.Item("zhj").Caption = zhj.Text
If DE1.rsrsSQ.State = 0 Then DE1.rsrsSQ.Open
tmpsql = "exec pCheckOut '" & Combo1.Text & "','" & txt_Date1.Text & "','" & txt_Date2.Text & "'"
'tmpsql = "select cpid,cpname,dj1,dj2,sum(amt) as amt,sum(thamt) as thamt,dw,sum(total1) as total1,sum(total2) as total2 from view_send where (amt>0 or thamt>0) and moddate>='" & txt_Date1.Text & "' and moddate<'" & DateAdd("d", 1, txt_Date2.Text) & "' and id=" & Combo1.ItemData(Combo1.ListIndex) & " group by cpid,cpname,dj1,dj2,dw order by cpid"
DE1.Commands.Item("rsSQ").CommandText = tmpsql
DE1.Commands.Item("rsSQ").Execute
DE1.rsrsSQ.Requery
DoEvents
rptGetMon.Refresh
rptGetMon.Show
指定label的显示和rptTextBox绑定的字段名称(和RS相对应)
例:
Report_RC.Sections(2).Controls(1).Caption = "名称" ‘label的显示
Report_RC.Sections(2).Controls(2).Caption = "规格型号"
Report_RC.Sections(2).Controls(3).Caption = "单 价"
Report_RC.Sections(2).Controls(4).Caption = "入库数量"
Report_RC.Sections(2).Controls(5).Caption = "单 位"
Report_RC.Sections(2).Controls(6).Caption = "购入日期"
Report_RC.Sections(2).Controls(7).Caption = "购入单位"
Report_RC.Sections(3).Controls(1).DataField = "名称" ’rptTextBox绑定的字段名称
Report_RC.Sections(3).Controls(2).DataField = "规格型号"
Report_RC.Sections(3).Controls(3).DataField = "单价"
Report_RC.Sections(3).Controls(4).DataField = "数量"
Report_RC.Sections(3).Controls(5).DataField = "单位"
Report_RC.Sections(3).Controls(6).DataField = "购入日期"
Report_RC.Sections(3).Controls(16).DataField = "购入单位"
Private Sub DataReport_Initialize()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Sql As String
'连接数据库(ODBC)
Set cn = New ADODB.Connection
With cn
.Provider = "MSDataShape.1" '一定要加这句
.Open "数据源名称","用户ID","密码"
End With
'组合查询语句:
Sql = "SELECT * FROM TableName " & _
"where ID ='" & Form1.Text1.text & "'"
'打开查询记录集
rs.Open Sql, cn, adOpenStatic, adLockReadOnly
Set Me.DataSource = rs
End Sub
也可以用绑定的方法,在细节中用RptTextBox控件按自己的打印要求布局。将其DataField属性对应相应的字段,注意不要设置DataMember,双击DataReport,添加代码如下:
Private Sub DataReport_Initialize()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Sql As String
'连接数据库(ODBC)
Set cn = New ADODB.Connection
With cn
.Provider = "MSDataShape.1" '一定要加这句
.Open "数据源名称","用户ID","密码"
End With
'组合查询语句:
Sql = "SELECT * FROM TableName " & _
"where ID ='" & Form1.Text1.text & "'"
'打开查询记录集
set rs=cn.execute(Sql)
Set Me.DataSource = rs
End Sub