Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15765

5.0 Pass type as the parameter to a method

$
0
0
i need to pass the Type as the parameter of the function and use it.
the Extension method is providing a short cut to extract the cell value of the datatable.

c# Code:
  1. /// <summary>
  2.         /// Returns data row information based on key column & keyId value
  3.         /// </summary>
  4.         /// <param name="Dt"></param>
  5.         /// <param name="IDcolumnName"></param>
  6.         /// <param name="IDvalue"></param>
  7.         /// <param name="GetColumnName"></param>
  8.         /// <returns>DataRow</returns>
  9.         public static DataRow GetCellValueByIdField(this DataTable Dt,
  10.                                                  String IDcolumnName ,
  11.                                                  Object IDvalue ,
  12.                                                  Type IDcolumnType ,
  13.                                                  String GetColumnName )
  14.                                                  
  15.         {
  16.             if (Dt == null && Dt.Rows.Count <= 0 )
  17.             {
  18.                 return null;
  19.             }
  20.  
  21.             // Here Filed<type> is to be solved
  22.             // Error @
  23.             // where OpRow.Field<IDcolumnType>(IDcolumnName).Equals(IDvalue)
  24.             // the error is Can't use the type variable , it must be explicit type instead of a variable name
  25.  
  26.  
  27.             var Dr = from OpRow in Dt.AsEnumerable()
  28.                      where OpRow.Field<IDcolumnType>(IDcolumnName).Equals(IDvalue)
  29.                      select OpRow;
  30.  
  31.             return Dr.FirstOrDefault();              
  32.            
  33.  
  34.  
  35.         }
hoe to fix it please

Viewing all articles
Browse latest Browse all 15765


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>