【问题标题】:Add all table names of my database to combo Box将我的数据库的所有表名添加到组合框
【发布时间】:2011-04-02 05:31:19
【问题描述】:
public void show()
{
       ds = new DataSet();
       ada = new SqlDataAdapter("select * from    sys.tables", conn);
       //ada = new SqlDataAdapter("select * from emp",    conn);
       //ds = new DataSet();
       ada.Fill(ds);
}  

private void Form1_Load(object sender, EventArgs    e)
{
       conn = new SqlConnection(@"Data Source=ASHISH-PC\SQLEXPRESS; initial    catalog=ashish; integrated security=true");
       show();
       foreach (DataTable dt in ds.Tables)
       {
           comboBox1.Items.Add(dt.TableName[0]);
       }
}

【问题讨论】:

标签: c# .net dataset


【解决方案1】:

我猜你只是在寻找快速而肮脏的东西。当前,您正在返回 DataTable 对象的名称。你需要这样的东西:

            foreach (DataTable dt in ds.Tables)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    comboBox1.Items.Add(dr[0].ToString());
                }
            }

就像我说的,又快又脏。

【讨论】:

    猜你喜欢
    • 2011-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2017-03-03
    • 2013-01-25
    • 2012-09-17
    • 1970-01-01
    相关资源
    最近更新 更多