Code use in RS

  • Hi All

    I would like to be able to do something like the following via the code option in RS

    Text field = Code.BldTypes("BuildingTypes") where ("BuildingTypes") is a dataset of the report

    Public Function BldTypes(ByVal DT As DataTable) As String

    For Each DR As Datarow In DT.Rows

    If BldTypes.ToString.Length > 0 Then

    BldTypes = DR("BuildingClass")

    Else

    BldTypes = BldTypes & " " & DR("BuildingClass")

    End If

    Next

    End Function

    This function, as written throws errors

    Can anyone point me to the corrcet suntax to use

    Many Thanks

  • What error message is being thrown?

  • To start with, you're passing "BuildingTypes" which is a string, not an object (i.e. a DataTable).

    If anyone out there knows how to pass the "object" to code, please post.

    As an alternative, it looks like you're attempting to build up a list / string of the "BuildingClass" column from the "BuildingTypes" result set. In you code block, declare a variable (string) then append the string from multiple calls on a standard table object. Something like:

    Dim TypeList

    Public Function GetType(type as string) as string

    TypeList = TypeList & " " & type

    Return TypeList

    End Function

    Call GetType from each row in your table, then link your text box to the last (final) row.

  • Hi There

    Thanks for your reply.

    Yes I am try to build up a string of values.

    Interestingly if I do the following

    Public Function BldTypes(ByVal DT As DataSet) As String

    This line does not throw an error however

    For Each DR As Datarow In DT.Rows

    Throws errors at Datarow...RS does not understand a Datarow

    Cheers

  • Try accessing anything else in your datatable and see if that throws an error (I suspect it will).

  • I suspect you a correct too...now if I could pass the Dataset as an object then...

    Still...dont understand why RS does not "understand" what a Datarow is

    Thanks

  • I don't think RS does type checking until you actually try to access a method. Therefore, it's trying to get a Datarow out of a string and can't.

    Of course, I could be wrong. Anyone?

  • Just a quick question

    What is the syntax to address the "Last" Column of Table which in this case has only one column.

    HTMS

    Cheers

  • andre (1/7/2008)


    Hi There

    Thanks for your reply.

    Yes I am try to build up a string of values.

    Interestingly if I do the following

    Public Function BldTypes(ByVal DT As DataSet) As String

    This line does not throw an error however

    For Each DR As Datarow In DT.Rows

    Throws errors at Datarow...RS does not understand a Datarow

    Cheers

    DataSet doesnt have DataRows, they have DataTables that have DataRows. Try

    For Each DR As Datarow In DT.Tables(0).Rows

    And for consistency sake change DT -> DS

    As for addressing the last column, youc an do something along the lines of

    DR(DT.Tables(0).Rows.Count-1)

    Cheers

    Andrew

  • Thanks for your reply

    Sorry Did not make myself clear 🙂

    When trying to declare DR as Datarow in the Code window of report, RS throws an error

    Datarow does not seem to be understood by the RS "combiler" if thats the correct term for it.

    As to my second problem

    Im trying to understand the sytax for retrieving a value from a column from the last row of a table which is hidden on my report

    eg x=last(Fields!Table5.Value) ...in other word how do I specify the column?

    Thanks

  • andre (1/7/2008)


    Thanks for your reply

    Sorry Did not make myself clear 🙂

    When trying to declare DR as Datarow in the Code window of report, RS throws an error

    Datarow does not seem to be understood by the RS "combiler" if thats the correct term for it.

    As to my second problem

    Im trying to understand the sytax for retrieving a value from a column from the last row of a table which is hidden on my report

    eg x=last(Fields!Table5.Value) ...in other word how do I specify the column?

    Thanks

    I think I understood your original issue and I still think its to do with the fact that DataSet does not contain a definition for Rows, you must address the table first, then rows.

    On the other issue, is your problem to do with finding the last row? or the data in a column?

    as you address rows via index, you can use the same construct as I posted earlier, ie

    //This will get the last row

    DataRow myRow = DS.Tables(0).Rows(DS.Rows.Count-1)

    Dim myValue as String

    //This will get the value of the last column into a string variable

    myValue = myRow(DS.Tables(0).Columns.Count-1)

    Cheers

    Andrew

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply