Search code examples
vb.netjson.net

Fill RDLC report with Json Vb.net


I'm trying to fill out the RDLC report with Json, but it doesn't return anything other than the columns.

How it shows

I got this Json result:

[
    {
        "ID": "11",
        "grade": "1",
        "netweight": "10.00",
        "code": "1",
        "initials": "CFF",
        "specie": "Tilapia",
        "scientificname": "Pende",
        "activity": "Offloading Truck",
        "voyage": "CFF2208",
        "vessel": "CHICOA FISH FARM",
        "currentbatch": "0",
        "tprocessID": "PRC01",
        "batchno": "123"
    }
]

I created a Json Property:

Namespace Data

    Public Class Tilapia
        <JsonProperty("grade")>
        Public Property grade As String

        <JsonProperty("netweight")>
        Public Property netweight As Decimal

        <JsonProperty("specie")>
        Public Property specie As String

        <JsonProperty("voyage")>
        Public Property voyage As String

        <JsonProperty("batchno")>
        Public Property batchno As String

        <JsonProperty("scientificname")>
        Public Property scientificname As String

    End Class

Fetch data:

Public Class Custom_batch

    Public Shared Function GetTilapia() As List(Of Tilapia)
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
        request = DirectCast(WebRequest.Create("http://127.0.0.160/v2/api/tilapia/tilapia/read_distinct.php"), HttpWebRequest)
        request.Headers("Authorization") = "46464-44874-444469-554777"
        response = DirectCast(request.GetResponse(), HttpWebResponse)
        reader = New StreamReader(response.GetResponseStream())
        Dim rawresp As String
        rawresp = reader.ReadToEnd()
        Dim results As List(Of Tilapia) = New List(Of Tilapia)()
        results = JsonConvert.DeserializeObject(Of List(Of Tilapia))(rawresp)
        Return results
        MsgBox(results)
    End Function
End Class

Then I build the class, and added to the project the .DLL file in the references, Then Added to Dataset and selected the datasource (Its strange that I can't find the GetTilapia() function in the Available Datasets).

Datasets

Tried to run but only returns the columns.

What am I doing Wrong?


Solution

  • Fixed by adding the GetTilapia() function code in my project, then called:

    ReportViewer1.LocalReport.DataSources.Clear()
    Dim rds = New ReportDataSource("DataSet1", GetTilapia())
    ReportViewer1.LocalReport.DataSources.Add(rds)
    ReportViewer1.RefreshReport()