Set datasource at runtime ActiveReports 10

122 Views Asked by At

I try to set datasource at runtime in my report of Activereports 10.

i have this code in the script :

'''

Sub ActiveReport_ReportStart

Dim connectionString = “Data Source=PC\SQLEXPRESS;Initial Catalog=Contratti;Integrated    Security=True”

Dim con As SqlConnection = New SqlConnection(connectionString)
con.Open()

Dim _strSQL As String = "Select id , cod from customers"

Dim _cm As New SqlClient.SqlCommand(_strSQL, con)

Dim _dt As New DataTable
Dim _da As New SqlClient.SqlDataAdapter(_cm)
_da.Fill(_dt)
_dt.TableName = "customers"
Me.DataSource = _dt

End Sub

'''

I have the error :

localhost:52620

Error: Report Script Compile Error on line 50 :

‘DataSource’ non è un membro di ‘Script.ReportScript’

What can i control ?

i’d like load my datatable at runtime and set it to the report .

Thank you

1

There are 1 best solutions below

0
Bart McEndree On

When using vb script I think you must use "rpt." instead of "Me."

Also, including your connectionString within the ActiveReport scripts is a bad idea. RPX files are not secure. See AR2pro.

Using AddCode and AddNamedItem methods the scripts can be cut down to simply

Sub OnDataInitialize
    set rpt.datsource.recordset = vbcode.getrset
End Sub