DataTable调试

就是在调试 程序 时,中断后,想要查看这时的一个DataTable中的内容,可是把这个DataTable加入到监视窗口中查看这个DataTable实在是困难,这个DataTable的内容可以一层层的打开,可是就是难以简洁而清楚的查看DataTable中的内容。   哪位有办法简洁而清楚的查看DataTable中的内容?  

方法一:主要用于winForm,也可用于webForm,但显示的不太好看,测试过,绝对可用
  using   System;  
  using   System.Data;  
  using   System.IO;  
  using   System.Text;  
   
  public   class   TableDebuger  
  {  
  static   public   string   GetInfo(DataTable   t)  
  {  
  DataRowCollection   rows=t.Rows;  
  StringBuilder   sb=new   StringBuilder();  
  sb.Append("DataTable:").Append(t.TableName)  
  .Append("/nRows   Count:").Append(rows.Count)  
  .Append("/n");  
   
  int   l=rows.Count;  
  for(int   i=0;i<l;i++)  
  {  
  DataRow   row=rows[i];  
  sb.Append("/nRow:").Append(i).Append("/n");  
  foreach(DataColumn   c   in   t.Columns)  
  {  
  sb.Append(c.ColumnName.PadRight(16,'   ')).Append(row[c]).Append("/n");  
  }  
  }  
  return   sb.ToString();  
  }  
  }  
  namespace   LostinetSample  
  {  
   
  class   Class1  
  {  
  [STAThread]  
  static   void   Main(string[]   args)  
  {  
  DataSet   ds=new   DataSet();  
  ds.ReadXml(new   StringReader(  
  @"  
  <data>  
  <t>  
  <a>3</a>  
  <b>4</b>  
  </t>  
  <t>  
  <a>x</a>  
  <b>y</b>  
  </t>  
  </data>  
  "  
  ),XmlReadMode.InferSchema);  
   
  //在下面设置断点.在命令窗口(Ctrl+Alt+I)里输入:TableDebuger.GetInfo(ds.Tables[0])/n  
  Console.Write("ok");  
  }  
  }  
  }  

方法二:
     /// <summary>
    /// 自己写的调试datatable
    /// </summary>
    /// <param name="text"></param>
   private void debugoutput(DataTable text)
   {
       int defaultrowwidth = 40;
       string thisrow1 = "";
       for (int c = 0; c <= text.Columns.Count - 1; c++)
       {
         
           thisrow1 +="["+ text.Columns[c].ColumnName.ToString()+"]";
           for (int tt = 0; tt <= defaultrowwidth - (text.Columns[c].ColumnName.ToString().Length+2) - 1; tt++)
           {
               thisrow1 += " ";
           }
      
      
       }
       System.Diagnostics.Debug.WriteLine(thisrow1);
    
       for (int i = 0; i <= text.Rows.Count - 1; i++)
       {
           string thisrow = "";
           for (int c = 0; c <= text.Columns.Count-1; c++)
           {
               thisrow += text.Rows[i][c].ToString();
               for (int tt = 0; tt <= defaultrowwidth - text.Rows[i][c].ToString().Length - 1; tt++)
               {
                   thisrow += " ";
               }
               
           }
           System.Diagnostics.Debug.WriteLine(thisrow);
       }
  
  
   } 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值