-1

I've been working with ASP.NET WebForms for a while and I've decided to try to convert some of my work into ASP.NET MVC.

Now, I can't figure out why my DataRow is null when there are results/rows.

Here is the code and error

Here is the code and error

string id= Session["role"].ToString() == "Admin" ? "0" : Session["emp_id"].ToString();

DataTable dt2 = getdata.accessAdmin(id);

DataRow[] dr = dt2.Select("default=0");

if (id != "0" && Session["emp_id"].ToString() != "0")
{
   <li>
     <a href="employee-dashboard"><i class="fa fa-arrow-left"></i><span>Back </span></a>
   </li>
}

foreach (DataRow row in dr)
{
   if (row["url"].ToString().Length > 1)
     {
       <li>
       <a href="@row["url"]">
       <i class="@row["icon"]"></i><span>
              @row["name"]
        </span>
       </a>
      </li>
     }
}

my getdata.cs :

public static DataTable accessAdmin(string id)
{
    return dbhelper.getdata("Select a.user_id,b.* from nobel_userRight a left join nobel_route b on b.id=a.route_Id where b.system=2 and a.user_id=" + id + " order by seqs asc");
}
ArunPratap
  • 4,816
  • 7
  • 25
  • 43
Jedge
  • 1
  • 2

1 Answers1

0

The Select("default=0"); doesn't look correct. Depending on the type of the default property, try changing the following line of code DataRow[] dr = dt2.Select("default=0"); to one of the below:

If the property is an int then use

DataRow[] dr = dt2.Where(r => r.default == 0);

If the property is a bool then use

DataRow[] dr = dt2.Where(r => r.default == false);
Jesse Johnson
  • 1,638
  • 15
  • 25