954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to display the data returned by select statement in a TextBox

Hi All,

Actually i want to dispaly the results of a select statement in a TextBox. Pls anyone give me an idea how to do it.

Thanks

nmakkena
Newbie Poster
14 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

MyTextBox.Text="result of select";
will show result of select in your textbox.
Otherwise use the (DataBindings) property

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
private void button1_Click(object sender, EventArgs e)
    {
      const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
      const string query = "Select * From Invoice Where InvNumber = @InvNumber";
      using (DataTable dt = new DataTable())
      {
        using (SqlConnection conn = new SqlConnection(connStr))
        {
          conn.Open();
          using (SqlCommand cmd = new SqlCommand(query, conn))
          {
            cmd.Parameters.Add(new SqlParameter("@InvNumber", 1100));
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
              dt.Load(dr);
            }
          }
          conn.Close();
        }
        if (dt.Rows.Count != 1)
          throw new Exception("Record not found!");
        DataRow row = dt.Rows[0];
        
        int invNumber = Convert.ToInt32(row["InvNumber"]);
        string invStatus = Convert.ToString(row["InvStatus"]);
        //Bind the text boxes after you have the values
        System.Diagnostics.Debugger.Break();
      }
    }
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You