Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datatable dt3 with some records. In one of the event I put 2 conditions, if
'currentable'=null and else. When I put the break point and verified , it enters the 'null' area
which it should not as dt3 has records. Because of this, variable 'v_MyCart' becomes zero which
I dont want to happen. My requirement is, since dt3 has records it has to go to the line 'if(dt3.Rows.Count>0' . Any wrong in my approach and code. I hereunder submit my code:

C#
DataTable dt3 = new DataTable();
                    dt3 = (DataTable)Session["ss"];
                    ViewState["CurrenTable"] = dt3;
                    if (ViewState["CurrentTable"]==null)
                    {
                        v_MyCart = 0;

                    }
                    else
                    {

                        if (dt3.Rows.Count > 0)
                        {
Posted

1 solution

C#
DataTable dt3 = new DataTable();
//First check is your session is null or not
if (Session["ss"] != null)
{
    dt3 = (DataTable)Session["ss"];
    ViewState["CurrenTable"] = dt3; //Now you have assigned a viewstate here
    if (((DataTable)ViewState["CurrentTable"]).Rows.Count == 0)
    { //Check assigned table has any rows or not
        v_MyCart = 0;
    }
    else //if (dt3.Rows.Count > 0)
    {//Data exists do something }
}
 
Share this answer
 

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