开发者

Good way to format data in a large DataTable

I have a large data.DataTable and some formatting rules to apply. I'm sure this is not a unique problem.

For example, the LASTNAME column has a value of "Jones" but my formatting rule requires it be 10 charac开发者_开发技巧ters padded with spaces on the right and uppercase only. Like: "JONES "

My initial thought is to loop through each row and generate a string. But, I wonder if I could accomplish this more efficiently with a DataView, LINQ or something else.

Can someone point me in a direction?


It really depends how you display the results. I would say if you display it in a grid, the easiest would be to do a quick loop, no real performance harm there in a datatable.

If you display the records individually you can create an extension method for your string, and simply call it like this for example. LastName.Padded()

public static class StringExtensions
{
   public static string Padded(this string s)
   {
       return s.ToUpper().PadRight(10);
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜