如何在组合框中显示多行的列 [英] how to show a column with multiple row in a combobox

查看:106
本文介绍了如何在组合框中显示多行的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想在组合框中显示列行。我只能把一个桌子的单元放在一个组合框中。我应该做什么?另一方面,我想显示第一行的column1,第二行的column1,第三列的column1和...



谢谢大家。

hi all,
i want to show a column rows in a combobox. and i just can put one cell of table in a combobox. what i must do? in the other hand i want to show first row of column1,second row of column1,third row of column1 and ...

thank you all.

推荐答案

参见示例:

See example:
using (SqlConnection sqlConnection = new SqlConnection("connectionString"))
{
    SqlCommand sqlCmd = new SqlCommand("SELECT column1 FROM tablename", sqlConnection);
    sqlConnection.Open();
    SqlDataReader sqlReader = sqlCmd.ExecuteReader();

    while (sqlReader.Read())
    {
        comboBox1.Items.Add(sqlReader["column1"].ToString());
    }

    sqlReader.Close();
}


这很简单,

It's pretty simple though,
SqlConnection con = new SqlConnection("DatabaseConnectionString");
SqlCommand cmd = new SqlCommand("SELECT SomeColumn FROM SomeTable", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

foreach(DataRow dr in dt.Rows)
{
    ComboBox1.Items.Add(dr[0].ToString());
}



-KR


-KR


这篇关于如何在组合框中显示多行的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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