用C#语言操作SQL数据库在做查询时如果没有DataGrid控件,查询出来的内容怎么不能显示在textBox控件上。请高人们多多指点 这个问题就是怎么把查询出来的信息和textBox控件绑定 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 datagrid 等控件包含collection元素,所以可以和dataset 之类的绑定。textbox 不能和collection 绑定你可以取出datatable 单独的一行中的一个字段把它赋给textbox,如:theTextBox.Text=dataset1.Tables[0].Rows[10]["myfield].ToString();也可以使用DataReader,如SqlCommand cmd = new SqlCommand("select username from thetable where id=1" , theConn);theConn.Open();SqlDataReader myReader = cmd .ExecuteReader();if(myReader.Read()) //应该是只有一行,所以不用while来移动记录了 theTextBox.Text=myReader.GetString(0)); 用DataReaderSystem.Data.SqlClient.SqlConnection conn=new System.Data.SqlClient.SqlConnection("server=localhost;uid=sa;pwd=sa;database=pubs"); System.Data.SqlClient.SqlCommand cmd=new System.Data.SqlClient.SqlCommand("select au_lname from authors",conn); conn.Open(); System.Data.SqlClient.SqlDataReader dr=cmd.ExecuteReader(); if (dr.Read()) { TextBox1.Text=dr["au_lname"].ToString(); } 设置textBox中的DataBindings里的Text属性 可以把textBox的Text属性绑定到相应的表的某个列,用的是DataBindings方法,还可以控制上下移动显示不同的条目。不过这个我好久没有动了,你可以看一下MSDN上的帮助,很详细的 用DataReader TextBox只能跟一行绑定 如何让窗口最小化后还照样运行,但不自动跳出来成为当前工作窗口 有谁知道可以利用下面的信息,生成TextBoxDesigner实例 寻找用于 Windows Mobile 5.0 Pocket PC SDK 的插件 sql数据库函数val不可识别 一个基础的问题? Sql数据插入access的大发现!不知道有人发现了没有?。。。。 谁有VS2005讲范型的资料啊? 用Delphi和asp.net开发windows application的优缺点! 关于在RichTextBox中显示位图 help! 发送邮件的问题 能不能让自己写的一个类的某些方法或者属性只公开给某些类???
也可以使用DataReader,如SqlCommand cmd = new SqlCommand("select username from thetable where id=1" , theConn);
theConn.Open();SqlDataReader myReader = cmd .ExecuteReader();
if(myReader.Read()) //应该是只有一行,所以不用while来移动记录了
theTextBox.Text=myReader.GetString(0));
System.Data.SqlClient.SqlCommand cmd=new System.Data.SqlClient.SqlCommand("select au_lname from authors",conn);
conn.Open();
System.Data.SqlClient.SqlDataReader dr=cmd.ExecuteReader();
if (dr.Read())
{
TextBox1.Text=dr["au_lname"].ToString();
}