Hi all,
I have a method that returns a sting array,
use this method here:
it works fine till I get all values then I got an error at: user.roleName
Object reference not set to an instance of an object.
I have a method that returns a sting array,
Code:
public string[] GetUserRoles(Guid _userId)
{
arr = new string[200];
userId = _userId;
int i = 0;
try
{
dbModule.InitConnection();
dbModule.cmd = new SqlCommand("SELECT RoleName FROM RolesTable WHERE (UserId = @UserID)", dbModule.con);
dbModule.cmd.Parameters.AddWithValue("UserID", userId);
dbModule.rdr = dbModule.cmd.ExecuteReader();
while (dbModule.rdr.Read())
{
roleName = dbModule.rdr["RoleName"].ToString();
if (dbModule.rdr.HasRows)
{
arr[i] = roleName;
i++;
}
else
{
i--;
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
dbModule.DestroyConnection();
}
return arr;
}
Code:
for (int i = 0; i < arr.Length; i++)
{
user.roleName = arr[i];
if (user.roleName.Equals("frmSecDailyEvents"))
objFrmMain.navPaNew.Visible = true;
if (user.roleName.Equals("frmPermanencyReg"))
objFrmMain.navPerm.Visible = true;
if (user.roleName.Equals("frmPatManage"))
objFrmMain.navPatManage.Visible = true;
if (user.roleName.Equals("frmExpenses"))
objFrmMain.navExpens.Visible = true;
}
}
Object reference not set to an instance of an object.
Comment