How to assign Custom class as datasource in crystal report

徘徊边缘 提交于 2019-12-23 07:38:53

问题


I created crystal report and through Data-->object i generated the DataSource and i added the fields from generated Datasource. My problem is, how to assign the values to the datasource.

Is anything like grid.DataSource = MyCustomClass is available. I can't access the Database directly [its a remove service]. What is the way to assign the values.

I want some thing like

    class CustomClass
    {
      string name;  
      string number;

       public string Name
       {
       set
       {
         return name;
       }
       }

       public string Number
       {
       set
       {
           return number;
        }
       }

    }
CustomClass custom = new CustomClass ();

custom.Name = "Mohan";
custom.Number = "100";

reportViewer.DataSource = custom ;

Is it anything similar to this is available.


回答1:


Take a look at this link:

https://msdn.microsoft.com/en-us/library/ms227595.aspx

It will show you how this can be done. You can view my answer on this question for an example. How to use Crystal Reports without a tightly-linked DB connection?

The quick explanation for this is that you should be able to add your custom object into an ArrayList and then use the ArrayList as the datasource. Hope this helps.



来源:https://stackoverflow.com/questions/1244711/how-to-assign-custom-class-as-datasource-in-crystal-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!