Я изучаю C # и использую Visual Studio 2010 для создания программы расчета заработной платы. Я получаю сообщение об ошибке «Не удается неявно преобразовать тип int в« короткий »».
Мой код:
private void btn_add_Click(object sender, EventArgs e)
{
try
{
// Get service instance
var employerPeriodService = Program.Kernel.Get<IEmployerPeriodService>();
// Get new code
var newCode = employerPeriodService.GenerateSAPCode();
// Create object
var employerPeriodAdd =
new EmployerPeriod
{
Code = newCode,
Name = newCode,
U_Tax_year = int.Parse(cb_tax_year.Text),
//U_Day_hrs = cb_number_hours.Text,
//U_Week_days = cb_number_days_week.Text,
//U_Week_hrs = txt_number_hours_week.Text,
//U_Month_days = cb_number_days_month.Text,
//U_Month_hrs = txt_number_hours_month.Text,
//U_Fortnight_days = cb_number_days_fortnight.Text,
//U_Fortnight_hrs = txt_number_hours_fortnight.Text,
//U_Weeks_in_month = cb_avg_weeks_month.Text,
//U_No_of_Fortnights = cb_avg_fortnights_month.Text,
U_Starting_period = Convert.ToDateTime(dateTimePicker1.Text),
U_Ending_period = Convert.ToDateTime(dateTimePicker2.Text)
//U_Comments = txt_comments.Text
};
// Save record
employerPeriodService.AddEmployerPeriod(employerPeriodAdd);
MessageBox.Show("Employer Payroll Period Added Successfully. Intake Ref: " + newCode.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch (RulesException ex)
{
MessageBox.Show(ex.GetErrorMessages(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
В Microsoft SQL Server, где находится моя база данных, U_Tax_year определяется как smallint. Что мне нужно сделать, чтобы решить эту ошибку. Преобразовать ли я то, что я получаю из поля со списком «cb_tax_year.Text», в int и как мне этого добиться.
Любая помощь приветствуется.