Dataset to ilistCode:
/// <Summary> ,
/// Replace dataset with a generic set
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
/// <Param name = "ds"> Dataset </Param>
/// <Param name = "tableindex"> Index of the data table to be converted </Param>
/// <Returns> </returns>
Public Static Ilist <t> datasettoilist <t> (Dataset ds, Int Tableindex)
{
If (DS = Null | Ds. Tables. Count < 0 )
Return Null ;
If (Tableindex> DS. Tables. Count- 1 )
Return Null ;
If (Tableindex < 0 )
Tableindex = 0 ;
Datatable dt = Ds. Tables [tableindex];
Ilist <t> result = New List <t> ();
For ( Int J = 0 ; J <DT. Rows. Count; j ++)
{
T _ t = (t) activator. createinstance ( Typeof (T ));
Propertyinfo [] propertys = _ T. GetType (). getproperties ();
Foreach (Propertyinfo pi In Propertys)
{
For ( Int I = 0 ; I <DT. Columns. Count; I ++)
{
If (PI. Name. Equals (Dt. Columns [I]. columnname ))
{
If (Dt. Rows [J] [I]! = Dbnull. value)
Pi. setvalue (_ T, DT. Rows [J] [I], Null );
Else
Pi. setvalue (_ t, Null , Null );
Break ;
}
}
} Result. Add (_ t );
} Return Result;
}
/// <Summary>
/// Replace dataset with a generic set
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
/// <Param name = "ds"> Dataset </Param>
/// <Param name = "tablename"> Name of the data table to be converted </Param>
/// <Returns> </returns>
/// Hpdv2806
Public Static Ilist <t> datasettoilist <t> (Dataset ds, String Tablename)
{
Int _ Tableindex = 0 ; If (DS = Null | Ds. Tables. Count < 0 )
Return Null ; If ( String . Isnullorempty (tablename ))
Return Null ;
For ( Int I = 0 ; I <Ds. Tables. Count; I ++)
{
If (Ds. Tables [I]. tablename. Equals (tablename ))
{
_ Tableindex = I;
Break ;
}
}
Return Datasettoilist <t> (DS, _ tableindex );
}
Personal favorites for learning !!!!