我将数据库中的数据插入到combobox
,现在我想将此combobox
的值显示在label
中,但每次都不是获取combobox
的值,我在System.Data.DataRowView
中获得了label
。
我使用此代码进行连接,它运行正常:
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();
然后我想使用此代码获取SelectedItem
:
label1.Text = cmbBooks.Items[cmbBooks.SelectedIndex].ToString();
如何解决?