Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can you please help me out with the c# code for the following scenario.


1. When I select a particular value in combo box, it must retrive its related information from the database and display on richtextbox .

2. How to convert the date time picker into string when I want to display the date in richtextbox from database.

3. How can I send an outlook email with the contents of the selected particular field in combobox.

for ref:

I have pasted the code .

C#
while (myReader.Read())
               {
                   string sEmployeeID = myReader.GetString("EmployeeID");
                   string sName = myReader.GetString("Name");
                   DateTime sFromDate = myReader.GetDateTime("FromDate");
                   DateTime sToDate = myReader.GetDateTime("ToDate");
                   string sSignum = myReader.GetString("Signum");
                   string sComment = myReader.GetString("Comment");
                   richTextBox1.Text = sEmployeeID;
                   richTextBox1.Text = sName;
                   richTextBox1.Text = sSignum;
                   richTextBox1.Text = sComment;
                   richTextBox1.Text = sFromDate;
                   richTextBox1.Text = sToDate;


               }

           }

           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
Posted
Updated 7-Sep-15 9:45am
v2

C#
richTextBox1.Text = sFromDate.ToString(/* add your formatting parameters here*/);

Note that each of your operations will overwrite the previous one. You should create the full text using a StringBuilder or similar before setting the text of the textbox.
 
Share this answer
 
Comments
rsk9 7-Sep-15 9:25am    
another question :
How can I display the content in text box in an order?
At present I can display the info in richtextbox but, its not in an order without spaces.
as eg:
XXX05058BATERfgfg9/4/2015 12:00:00 AM9/4/2015 12:00:00 AM.

What I like to see is as below with spaces in textbox.
XXX05058 BATER fgfg 9/4/2015 12:00:00 AM 9/4/2015 12:00:00 AM.
Richard MacCutchan 7-Sep-15 12:45pm    
Just add spaces and newline characters, wherever you need them.
Maciej Los 7-Sep-15 15:54pm    
5ed!
First way (recommended):
C#
StringBuilder sb = new StringBuilder();
sb.Append(sEmployeeID + " ");
//...
richTextBox1.Text = sb.ToString();


StringBuilder.Append Method[^]

Second way:
C#
richTextBox1.Text = sEmployeeID;
richTextBox1.Text += " " + sName;
richTextBox1.Text += " " + sSignum;
richTextBox1.Text += " " + sComment;
richTextBox1.Text += " " + sFromDate;
richTextBox1.Text += " " + sToDate;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900