Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:38:21+00:00 2026-05-28T19:38:21+00:00

I have a problem adding items to an Observable collection, I’ve tried a few

  • 0

I have a problem adding items to an Observable collection, I’ve tried a few things over the last few hours and still not making it threw debugging.

The error is Object reference not set to an instance of an object.

here is the code.

public class IPermissionData
{
    public UserListViewModel userListViewModel { get; set; }

    public UserListViewModel GetAllUsers()
    {
        List<string> userList = new List<string>();

        string sqlUsers = "select distinct username from DIMS_roles";
        DataTable tempUserTable = new DataTable();
        tempUserTable = Enviroment._database.GetResults(sqlUsers);

        for (int i = 0; i < tempUserTable.Rows.Count; i++)
        {
            if (tempUserTable.Rows[i]["username"].ToString() != null && tempUserTable.Rows[i]["username"].ToString() != "")
                userList.Add(tempUserTable.Rows[i]["username"].ToString());
        }

        foreach (string user in userList) 
        {
            if (user != null)
            {

                List<string> userPerm = new List<string>();
                string tempPermSql = string.Format("select role from DIMS_roles where username='{0}'", user);
                DataTable tempPermTable = new DataTable();
                tempPermTable = Enviroment._database.GetResults(tempPermSql);

                for (int i = 0; i < tempPermTable.Rows.Count; i++)
                {
                    if (tempPermTable.Rows[i]["role"].ToString() != null && tempPermTable.Rows[i]["role"].ToString() != "")
                        userList.Add(tempPermTable.Rows[i]["role"].ToString());
                }
                //UserViewModel userViewModel = new UserViewModel() { Permission = userPerm, PermCount = userPerm.Count(), UserName = user };
                userListViewModel.TheUsers.Add(new UserViewModel() { Permission = userPerm, PermCount = userPerm.Count(), UserName = user });
            }
        }
        return userListViewModel;
    }

    public IPermissionData() 
    {
        userListViewModel = new UserListViewModel(); 
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:38:22+00:00Added an answer on May 28, 2026 at 7:38 pm

    TheUsers observable collection should be instantiated in your view model class constructor. If not it is null – which is why you can’t add items to it. You can’t add items to something that doesn’t exist. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem adding entities to a collection. public void SaveNotificationUsergroups(int bookingobjectID, int[]
i have problem with simpleXml and adding new items. This is my xml: <?xml
I currently have a problem concerning the behaviour of floating items, and containers not
I have a problem adding ADO.Net Entity Data Model to my existing project, or
I have some problem with my .htaccess file. Here I am adding my problem.
I have a tabcontrol which binds to an observable collection of tabs. The tabcontrol
I have a thread adding items to a BlockingCollection . On another thread I
I have a simple (yet somehow convoluted) issue. Basically I'm adding items to make
i have a flow panel that i'm adding extra items to it at runtime
I have the following problem: I display items on a ListView and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.