Click here to Skip to main content
14,921,505 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
public void btn_abnrmalsixnine_Click(object sender, EventArgs e)
       {
           try
           {

               DataTable dt_temp = new DataTable();
               DataSet ds = (DataSet)ViewState["GridViewData"];

               DataTable DT_Main = ds.Tables[0];
               dt_temp = DT_Main.Clone();


              grv_NormalabnormalSummaryReport.Columns.FirstOrDefault();

               Session["AttendanceDate"] = grv_NormalabnormalSummaryReport.GetRowValues(grv_NormalabnormalSummaryReport.FocusedRowIndex, "AttendanceDate").ToString();
               Session["organization"] = grv_NormalabnormalSummaryReport.GetRowValues(grv_NormalabnormalSummaryReport.FocusedRowIndex, "Orgname").ToString();
               Session["OrgId "] = grv_NormalabnormalSummaryReport.GetRowValues(grv_NormalabnormalSummaryReport.FocusedRowIndex, "OrgId").ToString();
                   string organization = Session["organization"].ToString();
                   string AttendanceDate = Session["AttendanceDate"].ToString();
                   int OrgId = Convert.ToInt32(Session["OrgId "].ToString());
                 (ASPxGridView)grv_NormalabnormalSummaryReport.GetSelectedFieldValues();
                   dt_temp = DT_Main.AsEnumerable().Where(r => r.Field<DateTime>("AttendanceDate").ToString() == AttendanceDate
                                                     && r.Field<string>("AttendanceStatus").ToString() == "Abnormal" &&
                                                        r.Field<int>("TravelTime") >= 6 &&
                                                        r.Field<int>("TravelTime") <= 9).CopyToDataTable();

                   grv_EmployeeList.DataSource = dt_temp;
                   grv_EmployeeList.DataBind();
                   grv_details.Text = organization.ToString();
                   popupEmployeeList.ShowOnPageLoad = true;
                   return;






           }
           catch
           {

           }
       }


Please Help Me?

What I have tried:

Please give Me solution As soon as possible
Posted
Updated 23-Mar-21 2:54am
v2

C#
dt_temp = DT_Main.AsEnumerable().Where(r => r.Field<DateTime>("AttendanceDate").ToString() == AttendanceDate && r.Field<string>("AttendanceStatus").ToString() == "Abnormal" && r.Field<int>("TravelTime") >= 6 && r.Field<int>("TravelTime") <= 9).CopyToDataTable();

One of the problems with expressions like that, is that you cannot see any of the intermediate results. So split it into its constituent parts and see how many actual items it creates. Also, converting dates to strings in order to compare them is never a good idea. Use proper DateTime variables.
   
v2
Quote:
Please give Me solution As soon as possible

We can't. We have no access to your data, or the actual source, so there isn't anything we can do as you need the code running with the actual data in order to work out what might be wrong.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

And do yourself a big favour: Stop swallowing exceptions. When you write code like this:
C#
try
   {
   ...
   }
catch {}
You throw away all of the information you could use to fix a problem: the exception detail. Worse, you have no idea that an error occurred in the first place, let alone what line it might have happened on, so you can't even strat to fix it at the early stages when it's easiest.
Log them, show them on the debug console, do something useful with them - or remove your try ... catch block entirely as it just hiding problems until they become much, much worse.
   
Comments
Member 12700993 23-Mar-21 6:52am
   
I am trying Without try .... catch block but same error comes.
OriginalGriff 23-Mar-21 7:23am
   
And what did the debugger show you ...
Member 12700993 23-Mar-21 7:34am
   
Debugger show same error when i debug this line
dt_temp = DT_Main.AsEnumerable().Where(r => r.Field<datetime>("AttendanceDate").ToString() == AttendanceDate
&& r.Field<string>("AttendanceStatus").ToString() == "Abnormal" &&
r.Field<int>("TravelTime") >= 6 &&
r.Field<int>("TravelTime") <= 9).CopyToDataTable();
OriginalGriff 23-Mar-21 7:38am
   
:sigh:
The debugger doesn't remove errors, or fix errors: it lets you look at exactly what is happening; follow code while it's executing by single stepping; look at the content of your variables to find out if teh data looks like what you are expecting it to.

So start with your DataTable and look at what it holds: columns and rows. I suspect you will find that there are no rows - and possibly no columns either - so then you can look back through your code to find out why, using teh debugger to track what is happening.
Member 12700993 23-Mar-21 7:42am
   
Sir I am already check this DT_main Have data. there is so many rows and Column

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