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

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 13
Reputation: nmakkena is an unknown quantity at this point 
Solved Threads: 0
nmakkena nmakkena is offline Offline
Newbie Poster

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

 
0
  #1
Jun 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,999
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 294
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

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

 
0
  #2
Jun 20th, 2009
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,346
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 603
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

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

 
0
  #3
Jun 20th, 2009
  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. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC