当我在组合框中选择一个字段时,如何在富文本框中显示特定数据 [英] How can I display a particular data in rich text box when I select a field in the combo box
问题描述
能否帮我解决以下情况的c#代码。
1.当我在组合框中选择特定值时,它必须从数据库中检索其相关信息并显示在richtextbox上。
2.当我想在数据库中显示richtextbox中的日期时,如何将日期时间选择器转换为字符串。
3.如何发送outlook电子邮件使用组合框中所选特定字段的内容。
for ref:
我已粘贴了代码。
while (myReader.Read())
{
string sEmployeeID = myReader.GetString( 雇员跨度>);
string sName = myReader.GetString( 名称跨度>);
DateTime sFromDate = myReader.GetDateTime( FromDate);
DateTime sToDate = myReader.GetDateTime( ToDate);
string sSignum = myReader.GetString( Signum 跨度>);
string sComment = myReader.GetString( 注释跨度>);
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);
}
richTextBox1.Text = sFromDate.ToString(< span class =code-comment> / * 在此添加格式参数* / );
请注意,您的每个操作都将覆盖前一个操作。在设置文本框的文本之前,您应该使用StringBuilder
或类似内容创建全文。
第一种方式(推荐):
StringBuilder sb = new StringBuilder();
sb.Append(sEmployeeID + );
// ...
richTextBox1.Text = sb.ToString() ;
StringBuilder.Append方法 [ ^ ]
第二种方式:
richTextBox1.Text = sEmployeeID;
richTextBox1.Text + = + sName;
richTextBox1.Text + = + sSignum;
richTextBox1.Text + = + sComment;
richTextBox1.Text + = + sFromDate;
richTextBox1.Text + = + sToDate;
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 .
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);
}
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 aStringBuilder
or similar before setting the text of the textbox.
First way (recommended):
StringBuilder sb = new StringBuilder(); sb.Append(sEmployeeID + " "); //... richTextBox1.Text = sb.ToString();
StringBuilder.Append Method[^]
Second way:
richTextBox1.Text = sEmployeeID; richTextBox1.Text += " " + sName; richTextBox1.Text += " " + sSignum; richTextBox1.Text += " " + sComment; richTextBox1.Text += " " + sFromDate; richTextBox1.Text += " " + sToDate;
这篇关于当我在组合框中选择一个字段时,如何在富文本框中显示特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!