B
_birdy
Guest
Hi,
How can I overcome "Failed to convert parameter value from a User to Int32" error? I have checked inside my db, that @createdBy parameter is Int data type.
Below is some part of code from my UI and another is Parameter passing in my stored procedure,
_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();//added
_newNCSData.EnrolmentIntendedCourse.CourseID = _selectedIntendedCourse; //added
_newNCSData.RegisteredCourse = _returnCourse;//added
_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 = new Course();
specialFactorSetUp.IntendedCourse.CourseID = _registerdCourseId;
specialFactorSetUp.RegisteredCourse = _returnCourse;
specialFactorSetUp.EnrolmentIntendedCourse = new Course();
specialFactorSetUp.EnrolmentIntendedCourse.CourseID = _selectedIntendedCourse;
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);
Parameter passing
SqlCommand command = new SqlCommand("P_Foundation_AddNormalisedCompositeScoreSetup", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@enrolmentIntendedCourseId", SqlDbType.Int);
command.Parameters["@enrolmentIntendedCourseId"].Value = CompositeScoreData.EnrolmentIntendedCourse.CourseID;
command.Parameters.Add("@intendedCourseId", SqlDbType.Int);
command.Parameters["@intendedCourseId"].Value = CompositeScoreData.IntendedCourse.CourseID;
command.Parameters.Add("@weightingEducationalQualification", SqlDbType.Decimal);
command.Parameters["@weightingEducationalQualification"].Value = CompositeScoreData.WeightingEducationalQualification;
command.Parameters.Add("@weightingAdmissionTest", SqlDbType.Decimal);
command.Parameters["@weightingAdmissionTest"].Value = CompositeScoreData.WeightingEducationalAdmissionTest;
command.Parameters.Add("@status", SqlDbType.VarChar);
command.Parameters["@status"].Value = CompositeScoreData.Status;
command.Parameters.Add("@createdBy", SqlDbType.Int);
command.Parameters["@createdBy"].Value = CompositeScoreData.CreatedBy;
command.ExecuteNonQuery();
SqlCommand command = new SqlCommand("P_Foundation_AddNormalisedCompositeScoreSpecialFactorSetup", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@enrolmentIntendedCourseId", SqlDbType.Int);
command.Parameters["@enrolmentIntendedCourseId"].Value = CompositeScoreData.EnrolmentIntendedCourse.CourseID;
command.Parameters.Add("@intendedCourseId", SqlDbType.Int);
command.Parameters["@intendedCourseId"].Value = CompositeScoreData.IntendedCourse.CourseID;
command.Parameters.Add("@specialFactor", SqlDbType.Decimal);
command.Parameters["@specialFactor"].Value = CompositeScoreData.SpecialFactor;
command.Parameters.Add("@specialFactorDescription", SqlDbType.VarChar);
command.Parameters["@specialFactorDescription"].Value = CompositeScoreData.SpecialFactorDescription;
command.Parameters.Add("@status", SqlDbType.VarChar);
command.Parameters["@status"].Value = CompositeScoreData.Status;
command.Parameters.Add("@createdBy", SqlDbType.Int);
command.Parameters["@createdBy"].Value = CompositeScoreData.CreatedBy;
command.ExecuteNonQuery();
Continue reading...
How can I overcome "Failed to convert parameter value from a User to Int32" error? I have checked inside my db, that @createdBy parameter is Int data type.
Below is some part of code from my UI and another is Parameter passing in my stored procedure,
_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();//added
_newNCSData.EnrolmentIntendedCourse.CourseID = _selectedIntendedCourse; //added
_newNCSData.RegisteredCourse = _returnCourse;//added
_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 = new Course();
specialFactorSetUp.IntendedCourse.CourseID = _registerdCourseId;
specialFactorSetUp.RegisteredCourse = _returnCourse;
specialFactorSetUp.EnrolmentIntendedCourse = new Course();
specialFactorSetUp.EnrolmentIntendedCourse.CourseID = _selectedIntendedCourse;
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);
Parameter passing
SqlCommand command = new SqlCommand("P_Foundation_AddNormalisedCompositeScoreSetup", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@enrolmentIntendedCourseId", SqlDbType.Int);
command.Parameters["@enrolmentIntendedCourseId"].Value = CompositeScoreData.EnrolmentIntendedCourse.CourseID;
command.Parameters.Add("@intendedCourseId", SqlDbType.Int);
command.Parameters["@intendedCourseId"].Value = CompositeScoreData.IntendedCourse.CourseID;
command.Parameters.Add("@weightingEducationalQualification", SqlDbType.Decimal);
command.Parameters["@weightingEducationalQualification"].Value = CompositeScoreData.WeightingEducationalQualification;
command.Parameters.Add("@weightingAdmissionTest", SqlDbType.Decimal);
command.Parameters["@weightingAdmissionTest"].Value = CompositeScoreData.WeightingEducationalAdmissionTest;
command.Parameters.Add("@status", SqlDbType.VarChar);
command.Parameters["@status"].Value = CompositeScoreData.Status;
command.Parameters.Add("@createdBy", SqlDbType.Int);
command.Parameters["@createdBy"].Value = CompositeScoreData.CreatedBy;
command.ExecuteNonQuery();
SqlCommand command = new SqlCommand("P_Foundation_AddNormalisedCompositeScoreSpecialFactorSetup", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@enrolmentIntendedCourseId", SqlDbType.Int);
command.Parameters["@enrolmentIntendedCourseId"].Value = CompositeScoreData.EnrolmentIntendedCourse.CourseID;
command.Parameters.Add("@intendedCourseId", SqlDbType.Int);
command.Parameters["@intendedCourseId"].Value = CompositeScoreData.IntendedCourse.CourseID;
command.Parameters.Add("@specialFactor", SqlDbType.Decimal);
command.Parameters["@specialFactor"].Value = CompositeScoreData.SpecialFactor;
command.Parameters.Add("@specialFactorDescription", SqlDbType.VarChar);
command.Parameters["@specialFactorDescription"].Value = CompositeScoreData.SpecialFactorDescription;
command.Parameters.Add("@status", SqlDbType.VarChar);
command.Parameters["@status"].Value = CompositeScoreData.Status;
command.Parameters.Add("@createdBy", SqlDbType.Int);
command.Parameters["@createdBy"].Value = CompositeScoreData.CreatedBy;
command.ExecuteNonQuery();
Continue reading...