How to view a DataTable while debugging

前端 未结 4 594
南笙
南笙 2020-12-02 08:03

I\'m just getting started using ADO.NET and DataSets and DataTables. One problem I\'m having is it seems pretty hard to tell what values are in the data table when trying to

相关标签:
4条回答
  • 2020-12-02 08:17

    set the break point on the dataset/datatable(f9 shortcut key for break point) and run your application (f5 is the shortcutkey ) When the break point comes mouse hover the dataset/datatable click on the glass shown in the hover image in visual studio .

    Note : check compilation debug="true" is true in web config .Else visual studio wont go for debugging .

    0 讨论(0)
  • 2020-12-02 08:31

    I added two lines into my app inside a class named after the outermost class:

    public MyClass()
        {
          // The following (2) lines are used for testing only.  Remove comments to debug.
          System.Diagnostics.Debugger.Launch();
          System.Diagnostics.Debugger.Break();
        }
    

    This should stop the app and bring it up in debug mode. Then you can step through it and look at the values in your objects as you hover over them.

    0 讨论(0)
  • 2020-12-02 08:41

    With a break point set, after the DataTable or DataSet is populated, you can see a magnifying glass if you hover over the variable. If you click on it, it will bring up the DataTable Visualizer, which you can read about here.

    In this image you see below, dt is my DataTable variable and the breakpoint was hit a few lines below allowing me to hover over this value. Using Visual Studio 2008.

    alt text

    DataTable Visualizer (image credit):
    alt text

    0 讨论(0)
  • 2020-12-02 08:43
        /// <summary>
        /// Dumps the passed DataSet obj for debugging as list of html tables
        /// </summary>
        /// <param name="msg"> the msg attached </param>
        /// <param name="ds"> the DataSet object passed for Dumping </param>
        /// <returns> the nice looking dump of the DataSet obj in html format</returns>
        public static string DumpHtmlDs(string msg, ref System.Data.DataSet ds)
        {
            StringBuilder objStringBuilder = new StringBuilder();
            objStringBuilder.AppendLine("<html><body>");
    
            if (ds == null)
            {
                objStringBuilder.AppendLine("Null dataset passed ");
                objStringBuilder.AppendLine("</html></body>");
                WriteIf(objStringBuilder.ToString());
                return objStringBuilder.ToString();
            }
    
            objStringBuilder.AppendLine("<p>" + msg + " START </p>");
            if (ds != null)
            {
                if (ds.Tables == null)
                {
                    objStringBuilder.AppendLine("ds.Tables == null ");
                    return objStringBuilder.ToString();
                }
    
    
                foreach (System.Data.DataTable dt in ds.Tables)
                {
    
                    if (dt == null)
                    {
                        objStringBuilder.AppendLine("ds.Tables == null ");
                        continue;
                    }
                    objStringBuilder.AppendLine("<table>");
    
                    //objStringBuilder.AppendLine("================= My TableName is  " +
                    //dt.TableName + " ========================= START");
                    int colNumberInRow = 0;
                    objStringBuilder.Append("<tr><th>row number</th>");
                    foreach (System.Data.DataColumn dc in dt.Columns)
                    {
                        if (dc == null)
                        {
                            objStringBuilder.AppendLine("DataColumn is null ");
                            continue;
                        }
    
    
                        objStringBuilder.Append(" <th> |" + colNumberInRow.ToString() + " | ");
                        objStringBuilder.Append(  dc.ColumnName.ToString() + " </th> ");
                        colNumberInRow++;
                    } //eof foreach (DataColumn dc in dt.Columns)
                    objStringBuilder.Append("</tr>");
    
                    int rowNum = 0;
                    foreach (System.Data.DataRow dr in dt.Rows)
                    {
                        objStringBuilder.Append("<tr><td> row - | " + rowNum.ToString() + " | </td>");
                        int colNumber = 0;
                        foreach (System.Data.DataColumn dc in dt.Columns)
                        {
                            objStringBuilder.Append(" <td> |" + colNumber + "|" );
                            objStringBuilder.Append(dr[dc].ToString() + "  </td>");
                            colNumber++;
                        } //eof foreach (DataColumn dc in dt.Columns)
                        rowNum++;
                        objStringBuilder.AppendLine(" </tr>");
                    }   //eof foreach (DataRow dr in dt.Rows)
    
                    objStringBuilder.AppendLine("</table>");
                    objStringBuilder.AppendLine("<p>" + msg + " END </p>");
                }   //eof foreach (DataTable dt in ds.Tables)
    
            } //eof if ds !=null 
            else
            {
    
                objStringBuilder.AppendLine("NULL DataSet object passed for debugging !!!");
            }
            return objStringBuilder.ToString();
    
        } 
    
    0 讨论(0)
提交回复
热议问题