这个问题就是怎么把查询出来的信息和textBox控件绑定

解决方案 »

  1.   

    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));
      

  2.   

    用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();
    }
      

  3.   

    设置textBox中的DataBindings里的Text属性
      

  4.   

    可以把textBox的Text属性绑定到相应的表的某个列,用的是DataBindings方法,还可以控制上下移动显示不同的条目。不过这个我好久没有动了,你可以看一下MSDN上的帮助,很详细的
      

  5.   

    用DataReader TextBox只能跟一行绑定