如何在gridview asp.net中显示查询计划

时间:2014-09-17 07:08:11

标签: c# sql asp.net sql-server gridview

如何从sql server 2008向gridview asp.net显示查询计划

我的sql server 2008代码是

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
ORDER BY qs.total_logical_reads DESC 

我需要在gridview中显示输出

错误

gridview query_plan列没有显示数据...

<asp:TemplateField HeaderText="Query Plan" >
    <ItemTemplate>
          <asp:Label ID="lblPlan" Text='<%#Eval("query_plan") %>' runat="server" />
    </ItemTemplate>
</asp:TemplateField>

我犯了错误?

1 个答案:

答案 0 :(得分:0)

query_plan列是XML。

你需要HTML编码..

ASP.NET 4 +(注意#之后的冒号)

<asp:TemplateField HeaderText="Query Plan">
    <ItemTemplate>
        <asp:Label ID="lblPlan2" Text='<%#: Eval("query_plan") %>' runat="server" />
    </ItemTemplate>
</asp:TemplateField>

以前的版本

<asp:TemplateField HeaderText="Query Plan">
    <ItemTemplate>
        <asp:Label ID="lblPlan" Text='<%# System.Web.HttpUtility.HtmlEncode(Eval("query_plan").ToString())%>' runat="server" />
    </ItemTemplate>
</asp:TemplateField>