怎么在TextBox显示数据库里读取的数据?
我读取数据库,想修改它在上传,但不知道怎么在TextBox里显示数据,
请指点!!谢谢!

解决方案 »

  1.   

    string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders";
        SqlConnection myConnection = new SqlConnection(myConnString);
        SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
        myConnection.Open();
        SqlDataReader myReader;
        myReader = myCommand.ExecuteReader();
        // Always call Read before accessing data.
        if(myReader.Read()) 
        {
           textbox1.Text= myReader.GetString(1);//赋值
        }
        // always call Close when done reading.
        myReader.Close();
        // Close the connection when done with it.
        myConnection.Close();
      

  2.   

    if(dr.Read())
        {
           this.TextBox.Text=dr["姓名"].ToString();//
        }
      

  3.   

    SqlConnection conn = new SqlConnection("server=.;database=northwind;uid=sa;pwd=");
    SqlCommand cmd = new SqlCommand("select title from employees where employeeid=1", conn);
    conn.Open();
    TextBox1.Text = (string)cmd.ExecuteScalar();//读取返回记录的首行首列
    conn.Close();