Reputation: 207
I insert data from my database to combobox
, and now I want to display value of this combobox
into label
, but every time instead of getting value of combobox
, I get System.Data.DataRowView
in my label
.
I use this code for connection, it works fine:
OracleConnectionStringBuilder sb = new OracleConnectionStringBuilder();
sb.DataSource = "localhost";
sb.UserID = "library";
sb.Password = "library";
OracleConnection conn = new OracleConnection(sb.ToString());
conn.Open();
OracleDataAdapter TITLES = new OracleDataAdapter("SELECT NAME FROM TITLE", conn);
DataTable dt = new DataTable();
TITLES.Fill(dt);
cmbBooks.DisplayMember = "NAME";
cmbBooks.DataSource = dt;
conn.Close();
And then I want to get SelectedItem
using this code:
label1.Text = cmbBooks.Items[cmbBooks.SelectedIndex].ToString();
How to solve it?
Upvotes: 0
Views: 1727
Reputation: 39956
You can use the GetItemText
method:
label1.Text = cmbBooks.GetItemText(cmbBooks.SelectedItem);
Upvotes: 4