Answer the question
In order to leave comments, you need to log in
How to add data to table using combobox?
there are two tables, one of them is a reference book (in it ID and gender). There is a form for filling in the main table, when you fill in the data you simply indicate the ID, but you need the name of the gender (husband or wife). How to do it via combobox? so that the list with the gender (and not with the ID)
drops out, here are my attempts, it only shows the gender list in the combobox, but when filling it does not save the data to the table, the error gives the wrong data type
private void Form2_Load(object sender, EventArgs e)
{
//здесь привязка таблицы справочника
comboBox1.ValueMember = коммиссияПоДеламНесовершеннолетнихDataSet.Пол.IDColumn.ToString();
comboBox1.DisplayMember = коммиссияПоДеламНесовершеннолетнихDataSet.Пол.ПолColumn.ToString();
comboBox1.DataSource = полBindingSource;
}
private void button1_Click(object sender, EventArgs e)
{
//здесь код для заполнения с помощью текстбокса и комбобокса
var row = коммиссияПоДеламНесовершеннолетнихDataSet.ДанныеНесовершеннолетних.NewRow();
row[1] = textBox1.Text;
row[2] = textBox2.Text;
row[3] = textBox3.Text;
row[4] = textBox4.Text;
row[5] = textBox5.Text;
row[6] = comboBox1.Text;
коммиссияПоДеламНесовершеннолетнихDataSet.ДанныеНесовершеннолетних.Rows.Add(row);
try
{
this.Validate();
this.данныеНесовершеннолетнихBindingSource.EndEdit();
this.данныеНесовершеннолетнихTableAdapter.Update(this.коммиссияПоДеламНесовершеннолетнихDataSet.ДанныеНесовершеннолетних);
данныеНесовершеннолетнихBindingSource.MoveLast();
MessageBox.Show("Сохранить изменение?", "Сообщение", MessageBoxButtons.YesNo);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Answer the question
In order to leave comments, you need to log in
Lead by example. Ps that the police no longer rule? Before everything was in Fox.
https://docs.microsoft.com/en-us/dotnet/framework/...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question