B
_birdy
Guest
Hi,
I am trying to save user input data into a database. All of my data saving method are coming from WebService. I have assigned and initialized the data values to be ready to save in Webservice. But I am always getting 'Null' to most of them and that is the main issue: that I cannot save into database and getting 'object reference not set to an instance'error at the end of BtnSave method. I am wondering those data becomes Null because I initialized that become override my returned data ? If not, I am getting Object Reference not set error for those individual fields. I've searched online why Null Error occurs, because we haven't initialized variable. But, in my case I am not sure what is happening. Maybe I have initialized them, and returned data cannot be passed into?
I have 2 sps for this BtnSave method, 1st one has 6 parameters-@enrolmentIntendedCourseId,@intendedCourseId,@weightingEducationalQualification,@weightingAdmissionTest,@status and @created By. 2nd one also have 6 parameters-@enrolmentIntendedCourseId,@intendedCourseId,@specialFactor,@Description,@status and @createdBy.
_newNCSData.WeightingEducationalQualification = Convert.ToDecimal(txtWEQ.Text);
_newNCSData.WeightingEducationalAdmissionTest = Convert.ToDecimal(txtWAT.Text);
_newNCSData.Status="Active";
_newNCSData.IntendedCourse = new Course();
_newNCSData.IntendedCourse.CourseID = _registerdCourseId;
_newNCSData.EnrolmentIntendedCourse = new Course();
_newNCSData.EnrolmentIntendedCourse.CourseID = _selectedIntendedCourse;
_newNCSData.CreatedBy = new User();
_newNCSData.CreatedBy.UserId = AuthenticatedUser.UserSingleton.GetSingletonObject().userID;
if (resultGrid.RowCount > 0)
{
_newNCSSpecialFactorData= new List<NormalisedCompositeScoreSpecialFactorSetup>();
for (int i = 0; i < resultGrid.Rows.Count-1; ++i)
{
NormalisedCompositeScoreSpecialFactorSetup specialFactorSetUp = new NormalisedCompositeScoreSpecialFactorSetup();
if (resultGrid.Rows.Cells["NCSSpecialFactorSetupFoundationID"].Value.ToString() != string.Empty)
{
specialFactorSetUp.NormalisedCompositeScoreSpecialFactorSetupFoundationID = int.Parse(resultGrid.Rows.Cells["NCSSpecialFactorSetupFoundationID"].Value.ToString());
}
specialFactorSetUp.IntendedCourse.CourseID = _registerdCourseId;
specialFactorSetUp.SpecialFactor = Convert.ToDecimal(resultGrid["SpecialFactor", i].Value);
specialFactorSetUp.SpecialFactorDescription = Convert.ToString(resultGrid["Description", i].Value);
specialFactorSetUp.Status = "Active";
specialFactorSetUp.CreatedBy = new User();
specialFactorSetUp.CreatedBy.UserId = AuthenticatedUser.UserSingleton.GetSingletonObject().userID;
_newNCSSpecialFactorData.Add(specialFactorSetUp);
}
_calledFrom = "Save";
if (initialBackground.IsBusy == false)
initialBackground.RunWorkerAsync();
MessageBox.Show("Record is save successfully.", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information);
RefreshGrid();
Continue reading...
I am trying to save user input data into a database. All of my data saving method are coming from WebService. I have assigned and initialized the data values to be ready to save in Webservice. But I am always getting 'Null' to most of them and that is the main issue: that I cannot save into database and getting 'object reference not set to an instance'error at the end of BtnSave method. I am wondering those data becomes Null because I initialized that become override my returned data ? If not, I am getting Object Reference not set error for those individual fields. I've searched online why Null Error occurs, because we haven't initialized variable. But, in my case I am not sure what is happening. Maybe I have initialized them, and returned data cannot be passed into?
I have 2 sps for this BtnSave method, 1st one has 6 parameters-@enrolmentIntendedCourseId,@intendedCourseId,@weightingEducationalQualification,@weightingAdmissionTest,@status and @created By. 2nd one also have 6 parameters-@enrolmentIntendedCourseId,@intendedCourseId,@specialFactor,@Description,@status and @createdBy.
_newNCSData.WeightingEducationalQualification = Convert.ToDecimal(txtWEQ.Text);
_newNCSData.WeightingEducationalAdmissionTest = Convert.ToDecimal(txtWAT.Text);
_newNCSData.Status="Active";
_newNCSData.IntendedCourse = new Course();
_newNCSData.IntendedCourse.CourseID = _registerdCourseId;
_newNCSData.EnrolmentIntendedCourse = new Course();
_newNCSData.EnrolmentIntendedCourse.CourseID = _selectedIntendedCourse;
_newNCSData.CreatedBy = new User();
_newNCSData.CreatedBy.UserId = AuthenticatedUser.UserSingleton.GetSingletonObject().userID;
if (resultGrid.RowCount > 0)
{
_newNCSSpecialFactorData= new List<NormalisedCompositeScoreSpecialFactorSetup>();
for (int i = 0; i < resultGrid.Rows.Count-1; ++i)
{
NormalisedCompositeScoreSpecialFactorSetup specialFactorSetUp = new NormalisedCompositeScoreSpecialFactorSetup();
if (resultGrid.Rows.Cells["NCSSpecialFactorSetupFoundationID"].Value.ToString() != string.Empty)
{
specialFactorSetUp.NormalisedCompositeScoreSpecialFactorSetupFoundationID = int.Parse(resultGrid.Rows.Cells["NCSSpecialFactorSetupFoundationID"].Value.ToString());
}
specialFactorSetUp.IntendedCourse.CourseID = _registerdCourseId;
specialFactorSetUp.SpecialFactor = Convert.ToDecimal(resultGrid["SpecialFactor", i].Value);
specialFactorSetUp.SpecialFactorDescription = Convert.ToString(resultGrid["Description", i].Value);
specialFactorSetUp.Status = "Active";
specialFactorSetUp.CreatedBy = new User();
specialFactorSetUp.CreatedBy.UserId = AuthenticatedUser.UserSingleton.GetSingletonObject().userID;
_newNCSSpecialFactorData.Add(specialFactorSetUp);
}
_calledFrom = "Save";
if (initialBackground.IsBusy == false)
initialBackground.RunWorkerAsync();
MessageBox.Show("Record is save successfully.", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information);
RefreshGrid();
Continue reading...