JanOlMajti
JanOlMajti

Reputation: 1397

How do i get value from combobox, c#

I'm using forms and i get names from database to combobox. (Table Person(idPerson,name,age))

 this.personTableAdapter.Fill(this.test_pmDataSet.Person);

How can i get id from person, who i choose in combobox?

Upvotes: 2

Views: 824

Answers (2)

Moonlight
Moonlight

Reputation: 708

depending on which db you use:

i suppose you have your combobobox populate with the personnames out of your DB

  • get the name of the person by:

    string personsname= combobox1.selectedValue;

  • Get the id of this person by a query (sql: select idPerson from Persons where name = personsname;)

Upvotes: 3

anthares
anthares

Reputation: 11223

You probably need the "SelectedValue" property of your combobox control.

Upvotes: 6

Related Questions