Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

How to bind all tables in Database to dropdownlist.
Posted
Comments
[no name] 19-Jul-11 8:29am    
What you want to do?? if there is hundred table do you want to bind it all with dropdown.
Ashika s 20-Jul-11 0:48am    
please elaborate your question?

This is the query to get all the tables in a database.
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'

or
SELECT * FROM sys.tables

I hope you know how to bind to DropDownList[^].
 
Share this answer
 
v2
In the loweri have taken one table name REG and FieldName Stu_Name.you take as according to your database.
SqlConnection cn = new SqlConnection("PUT CONNECTION HERE");
    SqlDataAdapter ad;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        ad = new SqlDataAdapter("Select * from REG", cn);
        ad.Fill(ds, "REG");
        
       
        DropDownList1.DataSource = ds.Tables[0];
        DropDownList1.DataTextField = ds.Tables[0].Columns["Stu_Name"].ColumnName.ToString();
        DropDownList1.DataValueField = ds.Tables[0].Columns["Stu_Name"].ColumnName.ToString();
        DropDownList1.DataBind();
    }
 
Share this answer
 
v2
Which database u mean?
like MySql or MS-SQL or Oracle
 
Share this answer
 

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