数据不显示在c# RichTextBox

本文关键字:RichTextBox 显示 数据 | 更新日期: 2023-09-27 18:04:06

我有一个Sql Server连接到一个c#表单应用程序,显示数据字符串。在Sql Server端,所有三个实例中的数据都保存为varChar(MAX)。我只是想将数据显示到表单上的RichTextBox上。数据只显示有限数量的原始数据(出来作为不完整)在第一个RichTextBox (DataQualityTextBox),它不是显示在第二个和第三个RichTextBox (LoadFailureTextBox,和LoadPerformanceTextBox)。

这是我的代码:

SqlConnection conDataBase = new SqlConnection(constring);
                // POPULATING THE DATA QUALITY TAB
                Query = "SELECT " + notes_field1 + ", "+ notes_field2 + ", " + notes_field3 + " FROM  "+ database +" " +
                        " WHERE RunDate = '" + formattedDate + "'" +
                        " AND PackageName = '" + tdwl + "'" +
                        " AND Instance = '" + instance + "'; ";
                SqlCommand cmdDataBase = new SqlCommand(Query, conDataBase);
                SqlDataReader myReader;
                try
                {
                    conDataBase.Open();
                    myReader = cmdDataBase.ExecuteReader();
                    while (myReader.Read())
                    {
                        DataQualityTextBox.Text = myReader[0].ToString();
                        LoadFailureTextBox.Text = myReader[1].ToString();
                        LoadPerformanceTextBox.Text = myReader[2].ToString();
                    }
                    conDataBase.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

非常感谢!

数据不显示在c# RichTextBox

try:

while (myReader.Read())
                    {
                        DataQualityTextBox.Text += myReader[0].ToString();
                        LoadFailureTextBox.Text += myReader[1].ToString();
                        LoadPerformanceTextBox.Text += myReader[2].ToString();
                    }

while (myReader.Read())
                    {
                        DataQualityTextBox.AppendText(myReader[0].ToString());
                        LoadFailureTextBox.AppendText(myReader[1].ToString());
                        LoadPerformanceTextBox.AppendText( myReader[2].ToString());
                    }

在你的查询中使用参数代替串接字符串也是一个好主意