"Mick Walker" <ma**********@privacy.netwrote in message
news:5o************@mid.individual.net...
// get the number of columns
int intCols = myDataSet.Tables[0].Columns.Count;
// get the number of rows
int intRows = myDataSet.Tables[0].Rows.Count;
foreach (DataRow row in myDataSet.Tables[0].Rows) {
for(int i = 0; i < intCols ; i++) {
textBox2.Text += (string) row[i] + " , ";
}
textBox2.Text += Environment.NewLine;
}
It is taking a VERY long time, over 10 mins for less than 2000 rows.
Does anyone have any siggestions on making this faster?
I suspect that the problem may be in the string concatenations. Strings
in .Net are immutable, so every time that you change the string it has to be
discarded and a new string allocated instead. These operations are slow. It
should be faster if you use a StringBuilder:
using System.Text;
....
int intCols = myDataSet.Tables[0].Columns.Count;
int intRows = myDataSet.Tables[0].Rows.Count;
StringBuilder sb = new StringBuilder();
foreach (DataRow row in myDataSet.Tables[0].Rows) {
for(int i = 0; i < intCols ; i++) {
sb.Append((string) row[i] + " , ");
}
sb.Append(Environment.NewLine);
}
textBox2.Text = sb.ToString();