0

I get a NullReferenceException: Object reference not set to an instance of a object error while running the current function. The Database jobs table,

 public Dictionary<uint ,JobsFacotry> Jobs = new Dictionary<uint,JobsFacotry>();

 internal void LoadJobs(IQueryAdapter dbclient)
 {      
    dbclient.setQuery("SELECT * FROM jobs");
    DataTable jobs = dbclient.getTable();
    if (jobs != null)
    {
      Jobs.Clear();
      foreach (DataRow rows in jobs.Rows)
      {
        Jobs.Add((uint)rows["job_id"], new JobsFacotry((uint)rows["job_id"],
                 (uint)rows["room_id"], (string)rows["job_name"],
                 (string)rows["jobbadge"]));

      }

     }
  }

the error is at the Rows when i add the field to the db but they are correct http://prntscr.com/3jd7ud

BenMorel
  • 34,448
  • 50
  • 182
  • 322
oldink
  • 120
  • 11
  • 1
    which exact line does is produce the null exception on? – kevchadders May 15 '14 at 07:22
  • 1
    I guess your are trying to parse a value that does not exist. 1 of the values in 1 row is NULL – Dot_NET Pro May 15 '14 at 07:22
  • [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – dcastro May 15 '14 at 07:22
  • It is really unnerving to see two variables differ just for casing. – Steve May 15 '14 at 07:28
  • Put a breakpoint so you can at least identify which is the line who mess. And are you sure with the name of the column? Could you check it? –  May 15 '14 at 07:32
  • the error is on the line where the rows are entered but they do exist http://prntscr.com/3jd7ud – oldink May 15 '14 at 07:34
  • use debugger watch window for each of the elements in the row. this way you will be able to find the null element. – Zohar Peled May 15 '14 at 07:39
  • I can not debug i can build the solution and run it but debug wont work the button is just greyed out in the menu nor does f5 work – oldink May 15 '14 at 07:44
  • edit- Debuger watch windows gives me nothing its blank – oldink May 15 '14 at 07:49
  • you need to right click the rows element and select watch in the context menu that opens. – Zohar Peled May 15 '14 at 08:07

0 Answers0