Reputation: 201
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!
Upvotes: 0
Views: 476
Reputation: 14389
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
Upvotes: 1