Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have an Exception in my Live Application..DataTable Retrives another DataTable information..

C#
if (HttpContext.Current.User != null)
           {

               if (Session["username"] != null)
               {
                   string pageName = Page.Page.AppRelativeVirtualPath.Substring(Page.Page.AppRelativeVirtualPath.LastIndexOf('/') + 1);
                   DataTable dtFeatures2 = new DataTable();
                   dtFeatures2.Clear();
                   objMatermenuPL.usertype = Session["UserType"].ToString();
                   dtFeatures2 = objMastermenuBAL.GetMastermenu(objMatermenuPL);

                   DataView dt = new DataView(dtFeatures2);
                   dt.Sort = "fld_feature ASC";

                   if (dtFeatures2 != null)
                   {
                       foreach (Control control in leftpanel.Controls)
                       {
                           Type ty = control.GetType();
                           if (ty.Name.ToUpper() == "HTMLANCHOR")
                           {
                               int i = dt.Find(control.ID.Substring(3));
                               if (i < 0 && control.ID.Contains("lnk"))
                                   control.Visible = false;
                               if (control.ID.Contains("lnk") && control.ID.Substring(3) + ".aspx" == pageName)
                               {
                                   HtmlAnchor a = (HtmlAnchor)control;
                                   a.Attributes.Add("class", "active");
                               }
                           }
                       }
                   }


               }
           }
           else
           {
               Response.Redirect("~/Login.aspx");
           }

This code we use All most all master pages...If an exception Raise,then it comes directly
this line..
C#
dtFeatures2 = objMastermenuBAL.GetMastermenu(objMatermenuPL);

Message like : Cannot find column fld_feature.

"dtFeatures2" is Filled With Before Opened Page DataTable Information...

This exception gone after some..It's Working Fine 100%....Some times only shows these exception...
Posted
Updated 3-Feb-14 17:27pm
v3

1 solution

Try like this

C#
if (dtFeatures2 != null)
                   {
// below codes inside the condition...
                       DataView dt = new DataView(dtFeatures2);  
                       dt.Sort = "fld_feature ASC";
 
Share this answer
 
Comments
Karthik_Mahalingam 3-Feb-14 23:48pm    
see, if the Datatable is null then how will you do filter.. tell me ...
Karthik_Mahalingam 4-Feb-14 0:48am    
where it is filling ?
Karthik_Mahalingam 4-Feb-14 0:56am    
ok i got it.
Karthik_Mahalingam 4-Feb-14 0:58am    
in which line you are getting error ?
santhu888 4-Feb-14 1:02am    
And in every page,While loading datatable..... But some times we are getting these errors some times it's working properly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900