При попытке выбрать данные из комбобокса (place) возникает ошибка "Can't write CLR type System.String with handler type Int32Handler". Проверил всё, не могу понять, в чём проблема. В базе у первичных ключей тип serial4, у вторичных - int4
Вот код:
private void PlaceLoad()
{
drschool_Data.command = new NpgsqlCommand("select place_name from places", drschool_Data.conn);
drschool_Data.dataReader = drschool_Data.command.ExecuteReader();
List<string> elems = new List<string>();
while (drschool_Data.dataReader.Read())
{
elems.Add(drschool_Data.dataReader[0].ToString());
}
drschool_Data.dataReader.Close();
place.ItemsSource = elems;
}
private void InstrAdd1_Click(object sender, RoutedEventArgs e)
{
if (instr_name.Text != "" && birth_date.Text != "" && exp.Text != "" && place.SelectedIndex != -1)
{
drschool_Data.trans = drschool_Data.conn.BeginTransaction();
string selectedPlace = place.SelectedItem.ToString();
drschool_Data.command = new NpgsqlCommand("select id_place from places where place_name = :value1", drschool_Data.conn);
drschool_Data.command.Parameters.Add(new NpgsqlParameter(":value1", NpgsqlDbType.Varchar));
drschool_Data.command.Parameters[0].Value = selectedPlace;
int id_place = (int)drschool_Data.command.ExecuteScalar();
try
{
drschool_Data.command = new NpgsqlCommand("insert into instructors(snp_instr, birth_date_instr, experience, id_place) values(:value1, :value2, :value3, :value4)", drschool_Data.conn);
drschool_Data.command.Parameters.Add(new NpgsqlParameter("value1", NpgsqlDbType.Varchar));
drschool_Data.command.Parameters.Add(new NpgsqlParameter("value2", NpgsqlDbType.Varchar));
drschool_Data.command.Parameters.Add(new NpgsqlParameter("value3", NpgsqlDbType.Varchar));
drschool_Data.command.Parameters.Add(new NpgsqlParameter("value4", NpgsqlDbType.Integer));
drschool_Data.command.Parameters[0].Value = instr_name.Text;
drschool_Data.command.Parameters[1].Value = birth_date.Text;
drschool_Data.command.Parameters[2].Value = exp.Text;
drschool_Data.command.Parameters[3].Value = selectedPlace;
drschool_Data.command.ExecuteScalar();
drschool_Data.trans.Commit();
this.Close();
}
catch (Exception ex)
{
drschool_Data.trans.Rollback();
MessageBox.Show(ex.Message);
}
}
}
Буду очень рад, если поможете :(