c# - Object reference not set to an instance of an object, while sorting table column headers -


I get the following error in the browser see jTable followed by code and ran away: Object references are not set for an example of an object. I debug the code and on this line of code

  newlist = newlist.OrderBy (item = & gt; GetPropertyValue (item, Sort Expression)). ToList ();   

I get an error that I have confirmed by commenting this line of code.

I am trying to do sorting by killing the column header of the table but it is not doing it and gives an error out. Trying to find out on this for a few weeks, but it just does not seem to work. Public JsonResult TopPlayedInVenueList1 (String StartDate = "", String EndDate = "", "" ", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null) {try (If Request .IsAuthenticated == true) {string Path = @ "C: \\ 5Newwithdate-1k.xls"; OleDbConnection con = New OleDbConnection (@ "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = '" + Path + " 'Expanded Properties =' + (Four) 34 + "Excel 8.0; IMX = 1;" + (Four) 34 + ""; OleDbDataAdapter da = New OleDbDataAdapter ("Select [from [Sheet 1 $] to", Con) ; Con.Close (); System.Data.DataTable Data = New System.Data.DataTable (); da.Fill (Data); TopPlayed & gt; Daa = New list & topplayed & gt; ; Foreign currency (data. (Top of Play Plade Top = New Top-Play) (TrackID = Convert.ToInt32 (P. Field & lt; Double & gt; ("TrackID"), Date = P. Field & lt; DateTime ("Date Time") ("Times")}; TrackName = p.Field & lt; String & gt; ("TrackName"), ArtistName = P. Field & lt; String & gt; ("Artist name"), times = convert.ToInt32 (p. Field ("times")}} daa.Add (top);} var listOrder = daa.Where (i = & gt; ; I.Date & gt; = Convert.ToDateTime (StartDate) & amp; amp; i.Date & lt; = Convert toDateTime (EndDate). ToList (); if (jtStartIndex + 150> listOrder.ToList ( Calculation) {int val = listOrder.ToList (). Calculation - jtStartIndex; JtPageSize = val;} var newlist = listOrder.OrderByDescending (i = & gt; i.Date) .Olist (). GetRange (jtStartIndex, jtPageSize) ; If (string.IsNullOrEmpty (jtSorting)) {jtSorting = "Date ASC";} Sort Guidelines sortDirection = jtSorting.ToLower () Includes ("desc")? SortDirection.Desc: serialdate.a SIC; string sort exception = sort direction == sortdirection.decec? JtSorting.ToLower (). Change ("desc", ""): jtSorting.ToLower (). Includes ("asc")? JtSorting.ToLower () Change ("esk", ""): jtSorting; if (sortDirection == sortdirection.assc) {newist = newlist.orderbie (item = & gt; GetPropertyValue (item, sort expedition)). ToList (); } Else {newlist = newlist.OrderByDescending (item = & gt; GetPropertyValue (item, sort expansion)). ToList (); } Return Jason (New {Result = "OK", Records = New List, Total Record Coat = List Order Toolist (.)}}}; }

Edit: GetPropertyValue Method:

  GetPropertyValue public object (object obj, string propertyName) {obj == empty back? Tap: obj.GetType (). GetProperty (propertyName) .GetValue (obj, null); }    

Ensure your newList element and Sorting is a proper value.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -