Show all data table value into text box

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

To show all the values from a data table into a text box, you can iterate over the rows of the data table and concatenate the values into a string. Here's an example in C#:

csharp
// Assuming you have a DataTable called "dataTable" and a TextBox called "textBox1"

// Create a StringBuilder to hold the concatenated values
StringBuilder sb = new StringBuilder();

// Iterate over the rows of the DataTable
foreach (DataRow row in dataTable.Rows)
{
// Iterate over the columns of the current row
foreach (DataColumn column in dataTable.Columns)
{
// Append the value to the StringBuilder
sb.Append(row[column].ToString());
sb.Append(" "); // Add a space between values if desired
}

// Add a new line after each row if desired
sb.AppendLine();
}

// Set the text of the TextBox to the concatenated values
textBox1.Text = sb.ToString();

This code will iterate over each row of the DataTable, retrieve the value for each column, and append them to the StringBuilder. Finally, the text of the TextBox is set to the concatenated values.