简体   繁体   中英

Data not showing in C# RichTextBox

I have a Sql Server connected to a C# form application which displays data strings. On the Sql Server side the data is saved as varChar(MAX) in all three instances. I would just like to display the data onto a RichTextBox on the form. The data is only showing a limited amount of the original data (coming out as incomplete) in the first RichTextBox (DataQualityTextBox) and it is not showing on the second and third RichTextBoxes (LoadFailureTextBox, and LoadPerformanceTextBox).

This is my code:

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);
                }

Thank you very much!

try:

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

or

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

It will Also be a good idea to use parameters in your query instead of concatenating strings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM