日期:2014-05-20  浏览次数:20990 次

下拉菜单的帮定
private   void   Form1_Load(object   sender,   System.EventArgs   e)
{
String   connStr   =   "User   ID=sang;Data   Source= 'ora ';Password=sang; ";
OracleConnection   oracleConnect   =   new   OracleConnection(connStr);

OracleCommand   oracleCommand   =   new   OracleCommand();
oracleCommand.CommandText   =   "select   guojia   from   TEXT ";
oracleCommand.Connection=oracleConnect;


try  
{
oracleConnect.Open();  

OracleDataReader   odr   =   oracleCommand.ExecuteReader();

this.comboBox1.DataSource   =   odr;
this.comboBox1.DisplayMember   =   "guojia ";
this.comboBox1.ValueMember   =   "guojia ";
//this.comboBox1.DataBindings;
odr.Close();
}
catch(Exception   ex)  
{  
MessageBox.Show(ex.ToString());

}
finally
{
oracleConnect.Close();//使用完了链接一定要即时关闭
}


}


我现在在this.comboBox1.DataSource   =   odr;这句包错
说复杂的databinding接受ILIST或ILISTSOURCE作为数据源
我该如何下拉中帮定查找到的数据啊?


------解决方案--------------------
private void Form1_Load(object sender, System.EventArgs e)
{
String connStr = "User ID=sang;Data Source= 'ora ';Password=sang; ";
OracleConnection oracleConnect = new OracleConnection(connStr);


try
{

OleDbDataAdapter Adapter = new OleDbDataAdapter( "select guojia from TEXT ",oracleConnect);
DataSet ds = new DataSet();
Adapter.Fill(ds, "text ");
this.comboBox1.DataSource = ds;
this.comboBox1.DisplayMember = "guojia ";
this.comboBox1.ValueMember = "guojia ";
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());

}
finally
{
oracleConnect.Close();//使用完了链接一定要即时关闭
}


}