943,559 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1390
  • C# RSS
Jun 20th, 2009
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nmakkena is offline Offline
14 posts
since Dec 2008
Jun 20th, 2009
0

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

MyTextBox.Text="result of select";
will show result of select in your textbox.
Otherwise use the (DataBindings) property
Last edited by ddanbe; Jun 20th, 2009 at 1:03 pm.
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,735 posts
since Oct 2008
Jun 20th, 2009
0

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

c# Syntax (Toggle Plain Text)
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
  4. const string query = "Select * From Invoice Where InvNumber = @InvNumber";
  5. using (DataTable dt = new DataTable())
  6. {
  7. using (SqlConnection conn = new SqlConnection(connStr))
  8. {
  9. conn.Open();
  10. using (SqlCommand cmd = new SqlCommand(query, conn))
  11. {
  12. cmd.Parameters.Add(new SqlParameter("@InvNumber", 1100));
  13. using (SqlDataReader dr = cmd.ExecuteReader())
  14. {
  15. dt.Load(dr);
  16. }
  17. }
  18. conn.Close();
  19. }
  20. if (dt.Rows.Count != 1)
  21. throw new Exception("Record not found!");
  22. DataRow row = dt.Rows[0];
  23.  
  24. int invNumber = Convert.ToInt32(row["InvNumber"]);
  25. string invStatus = Convert.ToString(row["InvStatus"]);
  26. //Bind the text boxes after you have the values
  27. System.Diagnostics.Debugger.Break();
  28. }
  29. }
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: calling another form(frmreminder)
Next Thread in C# Forum Timeline: Polymorphism and WCF (httpbinding)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC