............................
............................
DataSet ds = this.GetDepartmentName();
this.comboBox1.DataSource = ds.Tables[0];后面应该怎么写啊?(我想把从数据库读出来的是数据绑定到comboBox1控件里面)
求完整代码!!!在线等
............................
DataSet ds = this.GetDepartmentName();
this.comboBox1.DataSource = ds.Tables[0];后面应该怎么写啊?(我想把从数据库读出来的是数据绑定到comboBox1控件里面)
求完整代码!!!在线等
for(int i = 0;i<=count;i++)
{
this.ComboBox.Items.Add(ds.Tabel[0].Row[i][0].ToString())
}
给分吧。。
001
002
003
.
.
.
.
要是我加"请选择"这么一个语句加在001前面,代码怎么写啊?
Combox 不是有个属性吗?Items属性,直接加一个试试。
this.combox.text = "请选择"
要不你直接在属性面板里去加就是了。
Text属性 填入 -- 请选择
string str ="server = (local);database = pubs;uid = sa;pwd = sa";
SqlConnection con = new SqlConnection();
con.ConnectionString = str;
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select pub_id from titles";
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
int count = ds.Tables[0].Rows.Count;
for(int i = 0;i<count;i++)
{
this.comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}这是全部代码
把查询语句改成你自己的表和数据库
要还是不行我也无能为力了.
Text属性在属性面板里去改一下就行了.