SIGN UP MEMBER LOGIN:    
ARTICLE

How To Get All Database Tables and TableColumns in Oracle

Posted by Ashish Singhal Articles | How do I November 08, 2005
In this article, I will show how can I fetch all tables and corresponding columns from an Oracle database using C# and Oracle .NET Data Provider.
Reader Level:

This source code shows how to get all database tables and their columns from an Oracle database using Oracle .NET Data Provider available in the .NET Framework class library.

To run this sample, you need to add your connection string to the following line:

OracleConnection connection = new OracleConnection("Connection String");

Here is the complete source code:

using System;
using
System.Data.OracleClient;
using System.Windows.Forms;
using System.Data;

Public Class Query :  System.Windows.Forms.Form
{
System.Windows.Forms.ListBox lstColumns;
System.Windows.Forms.ListBox lstTables;
 
Public Query()

    BindTables();
}
//Fill tables and columns into the listboxes
Private void
BindTables()
{
lstTables.Items.Clear();
//Execute the query.
try{
OracleConnection connection = new OracleConnection("Connection String");
OracleDataAdapter adap = new OracleDataAdapter ("select * from tabs"
, connection);
DataTable dt = new DataTable();
adap.Fill(dt);

//Display the table name from each row in the schema
foreach (DataRow row In
dt.Rows)
lstTables.Items.Add(row(
"Table_Name"
));
}
catch(
Exception ex)
{
MessageBox.Show("Error" + ex.Message, "Error");
}

}
//Table listBox select event to change columns in the colum listbox accordingly

Private void lstTables_SelectedIndexChanged(object sender, System.EventArgs)
{
lstColumns.Items.Clear();
//Select a table name.

string 
selTbl  = lstTables.SelectedItem.ToString();
try
{
//List the schema info for the selected table

OracleDataAdapter adap = new OracleDataAdapter("select column_name from user_tab_columns where table_name = '" + selTbl + "' order by column_id", connection);
DataTable
dt = new DataTable();
adap.Fill(dt);
foreach (DataRow row In
dt.Rows)
{lstColumns.Items.Add(row(
"column_name"));
}
}
catch(
Exception ex)
{MessageBox.Show(
"Error" + ex.Message, "Error");}

//Label for Column Names
lblListColumn.Text = "Column Names in " + selTbl +
" Table";
}
}

Login to add your contents and source code to this article
share this article :
post comment
 

thanks this will help me alot

Posted by asdullah khan ghalib Oct 15, 2010

Hi,

I am having oracle 9i installed in the server.

From the client machine I want to get all the 
database names(service names) which are available in the server through vb.net.

Also in SQLDMO , we have a method to get all available servers in the network as LISTAVAILABLESERVERS(). Like that, is there any method in oracle?

Kindly help me.

Regards,
Hema.

Posted by hema malini Oct 17, 2006

hai,

i used your coding for to oracle in asp.net (C#) But it mentioning the error as

UNABLE TO LOAD OCI.DLL

please reply us to

     sskanna82@gmail.com

vijaytvb@gmail.com

 

Posted by kannan s Feb 24, 2006

Someone was looking for it on forums.

Cheers!

Posted by Mahesh Chand Nov 08, 2005
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor