Click here to Skip to main content
15,070,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have tried to display the names of table in oracle database in visual studio 2012 in combo box but i am not sure why it is not displaying

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
con.Open();
OleDbDataAdapter oda = new OleDbDataAdapter("SELECT table_name FROM tabs where table_name Like 'ST%'", con);
DataTable dt = new DataTable();
oda.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "table_name";
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex + "");
}
}

What I have tried:

i Have researched and wrote this code but it still does not displays in the combo box.
Posted

Hello Nareen,

i would suggest that your SQL statement is false.
afaik this is MySQL and won't work with an OracleDB
SELECT table_name FROM tabs where table_name...


For Oracle you need this line of code (PL/SQL)
SELECT table_name, owner, tablespace_name FROM all_tables where table_name like...


the rest looks good :)
   
v2
Comments
Nareen Nair 14-Feb-16 8:41am
   
hanks sir for the reply. sir i try this also was not working. I have change the location of the code and now it works. I put the code in Form_Load. Then it works.
Nareen Nair 14-Feb-16 9:00am
   
sir can i ask something what would be the difference between displayMember and valueMember as i am confuse. I want it to appear exactly from the name of the table in my database so which 1 i use as both giving the same answer.
C#
private void Form2_Load(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                OleDbDataAdapter oda = new OleDbDataAdapter("SELECT table_name FROM tabs where table_name Not Like 'S%' AND table_name Not Like 'L%'", con);
                DataTable dt = new DataTable();
                oda.Fill(dt);
                comboBox1.DataSource = dt;
                comboBox1.DisplayMember = "table_name";
                
                
                con.Close();



            }

            catch (Exception ex)
            {
                MessageBox.Show(ex + "");
            }
         
        }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900