0

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

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by sknake
0

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

0
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();
      }
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.