为什么 ?到底是为什么? datareport1.datasource 一直出错
Private Sub DataReport_Initialize()
MsgBox "报表进入"
connstr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=lx;Data Source=chen"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
sql = "select 编号 from t_pos"
conn.Open connstr
rs.Open sql, conn, adOpenStatic, adLockBatchOptimistic
DataReport1.DataSource = rs
DataReport1.DataMember = sql
DataReport1.Sections("section2").Controls("label2").Caption = frmDataEnv.Text1.Text
End Sub
以上是我的代码 但是一直运行不过去,提示
datareport1.datasource 未找到方法和数据成员
我只是想给报表定义一个数据源,是我的类型不对呢,还是什么问题呢??
我该怎么去定义?
[解决办法]
这个示例代码够乱,搞不清你报表对象名称DataReport1 还是drt2,下面以DataReport1为准:
Private Sub DataReport_Initialize() connstr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=lx;Data Source=chen" Set conn = New ADODB.Connection Set rs = New ADODB.Recordset sql = "select 编号 from t_pos" conn.Open connstr rs.Open sql, conn, adOpenStatic, adLockBatchOptimistic set DataReport.DataSource =rs DataReport1.Sections("section1").Controls.Item("text1").DataField =rs.field(0).name