Visual Studio MVC integration, repeat data from store procedure

  • Hi !
    i have learning a lot if things about jsreport this week. I try to integrate it with visual studio because it will make things easier....

    I am trying to get data from stored procedure and its working but I can't make it work when I try to get more than one data and make it a table. I always get "IndexOutOfRangeException" and I believe its because of return function, here is the code :

    using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Threading.Tasks;
                using System.Data.SqlClient;
                using System.Collections;
            namespace NetWebApp.Model
             public class InvoiceModel
            public string ReferenceNumber { get; set; }
            public string AllocationType { get; set; }
            public string Contract { get; set; }
            public string EP { get; set; }
            public string json;
            public IEnumerable<ItemModel> Items { get; set; }
                public static InvoiceModel Example()
                ArrayList objs = new ArrayList();
                SqlConnection sqlConnection1 = new SqlConnection("Data 
                Catalog=PGPL_GMS_DEV;User ID=admin;Password=Password");  
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "[Approval].[rspSelAllocationSetupModification] '287','systemAdmin'";
                cmd.Connection = sqlConnection1;
                SqlDataReader rdr = cmd.ExecuteReader();
                // Data is accessible through the DataReader object here.
                    return new InvoiceModel()
                        { // I success to cal these data
                            ReferenceNumber = rdr["ReferenceNumber"].ToString(),
                            AllocationType = rdr["AllocationTypeName"].ToString(),
                            Contract = rdr["ContractNumber"].ToString(),
                            EP = rdr["AllocationPeriod"].ToString(),
                            Items = new List<ItemModel>()
                         //whenever I try to call these data (item model), they got me error
                          new ItemModel() {
                            AG = rdr["AllocationCategory"].ToString(),
                            AP = rdr["AllocationParameter"].ToString(),
                            CAM = rdr["CurrentAllocationMethod"].ToString(),
                            CF = rdr["CurrentAllocationFormula"].ToString(),
                            NAM = rdr["NewAllocationMethod"].ToString(),
                            NF = rdr["NewAllocationFormula"].ToString()
        public class ItemModel
            public string AG { get; set; }
            public string AP { get; set; }
            public string CAM { get; set; }
            public string CF { get; set; }
            public string NAM { get; set; }
            public string NF { get; set; }
            public string json { get; set; }

    I use as references.
    can anyone help ? Please .....
    thank you in advance

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.