C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

How to get the list of all tables in a database


Posted Date: 09 Jan 2005    Resource Type: Articles    Category: .NET Framework
Author: AbdouMember Level: Bronze    
Rating: 1 out of 5Points: 7



Introduction
Some time you need to give the user the ability to view the tables of a database, in spite of creating one page for each Table or writing the table name in the source code you can proceed like this:

use the OleDbSchemaGuid.Tables to get the database shema.
here is the source code :


private void Page_Load(object sender, System.EventArgs e)
{


//get table name to display in the datagrid

String T=Request.QueryString["T"];

//Open the connection to an access database ....
oleDbConnection1.Open();

//Define a Datatable
System.Data.DataTable dt;

// get the database Shema and put it in the Datatable
dt=oleDbConnection1.GetOleDbSchemaTable System.Data.OleDb.OleDbSchemaGuid.Tables,null);


//list database table and write name of each table in a label as link
foreach (DataRow row in dt.Rows)
if (row["TABLE_TYPE"].ToString()=="TABLE") {
Label1.Text+="<a href=?T="+row["TABLE_NAME"].ToString()+">"+ row["TABLE_NAME"].ToString()+"</a><br>" ;}

//when the user click on the link of a table:

if (T!=null){

// Create a DataAdapter base on the choosed table
System.Data.OleDb.OleDbDataAdapter da =new System.Data.OleDb.OleDbDataAdapter("Select * from ["+T+"]",oleDbConnection1);
DataSet ds = new DataSet("DataBase");
da.Fill(ds);

// Display the content in a datagrid

DataGrid1.DataSource=ds.Tables[0];
DataGrid1.DataBind();
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Differences between DataSet and DataReader
Previous Resource: Pagination
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use