C#textboxx 显示数据问题

来源:百度知道 编辑:UC知道 时间:2024/06/18 01:44:07
我现在想把SQL数据库里的数据,在textbox里面显示一个字段
请问命令该怎么写

DataTabe dt=//read from sql

this.textBox.text=dt.rows[0]["字段名"].ToString();

!!!!!!!!!!!!
请详细描述你的问题!!!!!!!!!

把SQL数据库里的数据,在textbox里面显示一个字段
什么意思??
你说的是数据库里面某个表的某行某列的记录值?
还是某个表的列明??
莫名其妙
----请详细描述你的问题 (此话已经说了五遍)

string name = SqlDataReader[0].ToString();//得到你数据库中的数据
comboBox1.Items.Add(name);//添加到combobox上

试一试。。。

foreach(Cell c in ds.tables["yourtable"].culomns["yourcolumn"])
{
combobox.items.add(c);
}

using(SqlConnection con=new SqlConnection("数据库连接"))
{
SqlCommand command=new SqlCommand();
SqlDataReader read=command.Ex..Reader();
if(read.Read())
{
textBox1.Text=read["数据库字段"].toString();
}
}

先用一个数据集比如dataTable,绑定数据库的数据

然后用this.textbox.databingding("text",datable,"属性名");即可