public string connectionString = @"User Id=admin;Password=admin;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= LOCALHOST)(PORT=1521))(CONNECT_DATA=(SID=orcl)));";
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string queryString = @"SELECT USER_ID,USERNAME FROM ALL_USERS";
try
{
OracleConnection oraConn = new OracleConnection(connectionString);
OracleCommand oraCmd = new OracleCommand(queryString, oraConn);
OracleDataAdapter oraDA = new OracleDataAdapter(oraCmd);
DataSet dataSt = new DataSet();
oraDA.Fill(dataSt);
oraConn.Close();
ComboBox1.DisplayMemberPath = "USERNAME";//绑定USERNAME字段
ComboBox1.ItemsSource = dataSt.Tables[0].DefaultView;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString());
}
}
WPF ComboBox绑定Oracle数据库指定字段的值
最新推荐文章于 2021-04-16 02:59:15 发布