如何将数据库中的所有表绑定到下拉列表 [英] How to bind all tables in Database to dropdownlist

查看:92
本文介绍了如何将数据库中的所有表绑定到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何将数据库中的所有表绑定到下拉列表.

Hi all,

How to bind all tables in Database to dropdownlist.

推荐答案

这是获取数据库中所有表的查询.
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


我希望您知道如何绑定到DropDownList [


I hope you know how to bind to DropDownList[^].


在低位中取了一个表名REG和FieldName Stu_Name.you根据您的数据库.
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();
    }


您的意思是哪个数据库?
像MySql或MS-SQL或Oracle
Which database u mean?
like MySql or MS-SQL or Oracle


这篇关于如何将数据库中的所有表绑定到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆