I created table N_Roles_Users
in my database, I want to show it's value if username matches with existing login user.
I wrote this code below. But it is generating exception that check if object is Null.
// currentUser="UserA";
public List<string> GetUserRoles( string currentUser)
{
N_Roles_Users allroles = new N_Roles_Users(); //N_Roles_Users is database table name.
List<string> roleslist = new List<string>();
List<char> temp = new List<char>();
temp = allroles.user_name.ToList();
List<char> tempa = new List<char>();
tempa = allroles.role_name.ToList();
for (int i = 0; i < temp.Count; i++) // Loop through List with for
{
if (currentUser == temp[i].ToString())
{
roleslist.Add(tempa[i].ToString());
MessageBox.Show(tempa[i].ToString());
}
}
return roleslist;
}
Can anyone guide me how to resolve this problem?