不填充我有以下ASP GridView控件:GridView控件使用數據綁定
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="TEXT" HeaderText="TEXT" SortExpression="TEXT" />
<asp:BoundField DataField="session_id" HeaderText="session_id" SortExpression="session_id" />
<asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />
<asp:BoundField DataField="command" HeaderText="command" SortExpression="command" />
<asp:BoundField DataField="cpu_time" HeaderText="cpu_time" SortExpression="cpu_time" />
<asp:BoundField DataField="total_elapsed_time" HeaderText="total_elapsed_time" SortExpression="total_elapsed_time" />
<asp:BoundField DataField="dbname" HeaderText="dbname" ReadOnly="True" SortExpression="dbname" />
<asp:BoundField DataField="user_running_query" HeaderText="user_running_query" SortExpression="user_running_query" />
</Columns>
</asp:GridView>
在後面的代碼我有:
protected void Page_Load(object sender, EventArgs e)
{
using (Repository.SqldbAllQueries())
{
GridView1.DataBind();
}
}
而且我的倉庫類包含:
public static class Repository
{
public static SqlDataReader SqldbAllQueries()
{
SqlConnection sqlConnection1 = new SqlConnection("Data Source=sqldb;Initial Catalog=ReportServer;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = @"SELECT sqltext.TEXT,req.session_id,req.status,req.command,req.cpu_time,
req.total_elapsed_time,DB_NAME(req.database_id) as dbname,s.login_name as user_running_query
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
INNER JOIN sys.dm_exec_sessions s ON req.session_id = s.session_id";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
}
我試圖捕獲每個當前正在運行的查詢在SQL數據庫和輸出在我的ASP頁面作爲網格視圖使用數據庫nd方法,代碼會生成並運行,但是gridview不會在頁面上顯示。我已經通過代碼,我可以看到reader
包含行,但我似乎錯過了這裏的東西,因爲它們沒有被添加到gridview,任何人都可以看到問題?
'DataBind'之前你需要設置'DataSource'屬性 – Grundy