0

My problem is that, I am not sure in which moment, my SQLite model stopped to be instantiated. To Insert the object in specific data table I use created service. This solution worked before without any problem. I was working on some completely different part (creating other database service) and at some point this is what happened.

SOPs is the Sqlite table model.

The problem refers to the intantiation of the SOPs class. I did not change a thing in the code I am 99% sure.

SOPs table exists.

System.NullReferenceException: 'Object reference not set to an instance of an object.*

Code:

private void Button_Click_1(object sender, RoutedEventArgs e)
      {
         //what happens when click -> Add SOP

        var sopService = new SOPsDbService();

        sopService.Insert(new SOPs
        {
            Description = this.textBoxDescription.Text,
            Standard = this.comboBoxStandard.SelectedValue.ToString(),
            Goal = this.textBoxTime.Text,
            FreqTimes = this.comboboxFreqTimes.SelectedValue.ToString(),
            FreqPeriod = this.comboboxFreqPeriod.SelectedItem.ToString()
        });




        //Then update SOP list
        //UpdateSOPList();

    }

Table model:

using SQLite.Net.Attributes;
using System;

namespace eCILT.Assets.Model.dbModels.SOPs
{
public class SOPs
{
    [AutoIncrement, PrimaryKey]
    public int Id { get; set; }

    public string Name { get; set; }
    public string ImageUrl { get; set; }
    public string Description { get; set; }
    public string Phase { get; set; }
    public string Standard { get; set; }
    public string CorrectiveActions { get; set; }
    public string Tools { get; set; }
    public string Control { get; set; }
    public string ResponsibleUnit { get; set; }
    public string Goal { get; set; }
    public TimeSpan Norm { get; set; }
    public string OplSop { get; set; }
    public string FreqTimes { get; set; }
    public string FreqPeriod { get; set; }
    public string SheNote { get; set; }
    public string Line { get; set; }
    public string DesignedBy { get; set; }
    public string ApprovedAM { get; set; }
    public string AprovedSHE { get; set; }
    public string AprovedBHP { get; set; }
    public DateTime ApprovedAmDate { get; set; }
    public DateTime ApprovedSheDate { get; set; }
    public DateTime ApprovedBhpDate { get; set; }

    //Foreign keys
    public int GroupId { get; set; }
    public int CategoryId { get; set; }
    public int MachineId { get; set; }

    public SOPs()
    {
        //empty
    }

    public SOPs(string name, string imageUrl, string desc, string goal, TimeSpan norm, string oplSop, string freqTimes, string freqPeriod, string sheNote, int machineId, string line, string designedBy, string approvedAm, DateTime approvedShe, DateTime approvedAmDate, DateTime approvedSheDate)
    {
        this.Name = name;
        this.ImageUrl = imageUrl;
        this.Description = desc;
        this.Goal = goal;
        this.Norm = norm;
        this.OplSop = oplSop;
        this.FreqTimes = freqTimes;
        this.SheNote = sheNote;
        this.MachineId = machineId;
        this.Line = line;
        this.DesignedBy = designedBy;
        this.ApprovedAM = approvedAm;
        this.ApprovedSheDate = approvedShe;
        this.ApprovedAmDate = approvedAmDate;
        this.ApprovedSheDate = approvedSheDate;
    }

}
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Maciej
  • 1
  • 1
  • 1
  • I know what NullReferenceExeption is. Question is why it happened without a change in code? Maybe something in the Sqlite configuration ? – Maciej Mar 11 '18 at 18:50
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Mar 12 '18 at 10:51

0 Answers0