| brian on Feb 22, 2007 at 8:26:44 AM (# 7) You need to read the data from the DefaultView instead of the table.
change from:
for(x = 0; x < dt.Rows.Count; x++) { tw.WriteLine(dt.Rows[x][0].ToString() + "\t" + dt.Rows[x][1].ToString() + "\t" + dt.Rows[x][2].ToString()); }
to either
foreach (DataRow row in dt.DefaultView) { tw.WriteLine(row[0].ToString() + "\t" + row[1].ToString() + "\t" + row[2].ToString()); }
or
for(x = 0; x < dt.Rows.Count; x++) { tw.WriteLine(dt.DefaultView[x][0].ToString() + "\t" + dt.DefaultView[x][1].ToString() + "\t" + dt.DefaultView[x][2].ToString()); }
This should work. Give that a try anyway and let me know what happens. Monte on Feb 22, 2007 at 8:51:18 AM (# 8)This is the solution I used:
for(x = 0; x < dt.Rows.Count; x++) { tw.WriteLine(dt.DefaultView[x][0].ToString() + "\t" + dt.DefaultView[x][1].ToString() + "\t" + dt.DefaultView[x][2].ToString()); }
It worked. Thanks a bunch!! brian on Feb 22, 2007 at 8:59:18 AM (# 9)cool. glad you got it sorted. ChrisRickard on Feb 22, 2007 at 1:49:27 PM (# 10)Pun intended? :D Monte on Feb 22, 2007 at 2:00:53 PM (# 11)Actually, now I have a third DataTable that won't sort...
I even tried the
foreach (DataRow row in dt.DefaultView) { tw.WriteLine(row[0].ToString() + "\t" + row[1].ToString() + "\t" + row[2].ToString()); }
But that gave me an error (Specified cast is not valid).
Well, the first two worked with the code I mentioned previously. My table structure is:
DataTable dt = new DataTable(); dt.Columns.Add("TEAM_NAME"); dt.Columns.Add("POWER_RANKING");
And the sort looks like this:
dtPower.DefaultView.Sort = "POWER_RANKING DESC";
But it never sorts correctly. I'm missing something, but I don't know what... Monte on Feb 22, 2007 at 2:30:41 PM (# 12)Never mind...I forgot to establish a variable type for one of the columns...problem solved. brian on Feb 23, 2007 at 12:48:51 AM (# 13)'fraid not Chris...never thought about it until you pointed it out :)
|