我有一个报表,数据环境用的是SQL语句,是从多个表中查询的数据,可是我有个查询过滤条件,根据不同的过滤条件会产生不同的SQL语句,其中,过滤条件的的数据字段、关系、和值都是不固定的,这样在数据环境中的SQL语句也应该跟着变,遇到这种情况该如何处理,请高手多多帮忙,急
如果分不够,我还可以加。

解决方案 »

  1.   

    我的EMAIL:SHERLOCK7610@YAHOO。COM。CN
      

  2.   

    你可以在程序中动态设置数据环境的command的数据来源简单示例下列代码引用自 lxqlogo0(群子)
    Private Sub Command3_Click()
    Dim objcon As New ADODB.Connection
    Dim objrs As New ADODB.Recordset
    objcon.Open "provider=sqloledb.1;user id=sa;password=csm@csm;datasource=;initial catalog=xiazaijiluziliao"
    objrs.Open "select * from table where name='& text1.text & "'", objcon, 1, 3
    Set DataGrid1.DataSource = objrs.DataSource
    'Me.Caption = objrs.RecordCount
    Set DataReport1.DataSource = DataGrid1.DataSource
    'DataReport1.DataMember = DataGrid1.DataMember
    With DataReport1
    .Sections(4).Controls("Label2").Caption = "共%P页第%p页"
    .Sections(2).Controls("label3").Caption = "打印日期:%d %t"'.Sections(3).Controls("Text1").DataMember = objrs.DataMember
    .Sections(3).Controls("Text1").DataField = "ziduan1"
    .Sections(3).Controls("Text2").DataField = "ziduan2"
    .Sections(3).Controls("Text3").DataField = "ziduan3"
    End With
    DataReport1.ShowEnd Sub
      

  3.   

    .Sections(3).Controls("Text1").DataField = "ziduan1"
    这句不好用,提示下标越界