0

我不知道为什么我的数据没有显示在我的 gridview 中,如果我使用具有相同查询的 sqldatasource 它可以工作。

cmd.Connection = conn
    conn.Open()
    cmd.CommandText = "SELECT DISTINCT TOP (100) PERCENT dbo.tblConfig_Agent.FirstName, dbo.tblConfig_Agent.LastName, SUM(dbo.tblData_DeviceByDevice.ACDCount) AS Calls, SUM(dbo.tblData_DeviceByDevice.ACDDuration) AS Seconds, dbo.tblConfig_AgentGroup.Name, dbo.tblConfig_Agent.Pkey FROM dbo.tblData_DeviceByDevice INNER JOIN dbo.tblConfig_AgentGroup ON dbo.tblData_DeviceByDevice.FKDevice2 = dbo.tblConfig_AgentGroup.Pkey INNER JOIN dbo.tblConfig_Agent ON dbo.tblData_DeviceByDevice.FKDevice1 = dbo.tblConfig_Agent.Pkey WHERE     (dbo.tblData_DeviceByDevice.MidnightStartDate BETWEEN '4/10/2011' AND GETDATE())GROUP BY dbo.tblConfig_Agent.FirstName, dbo.tblConfig_Agent.LastName, dbo.tblConfig_AgentGroup.Name, dbo.tblConfig_Agent.Pkey ORDER BY Seconds, dbo.tblConfig_Agent.FirstName, dbo.tblConfig_Agent.LastName"
    da.Fill(ds, "test")


    GridView2.DataSource = ds.Tables("test")
    GridView2.DataBind()
    conn.Close()
    UpdatePanel1.Update()
4

1 回答 1

2

我认为您必须查看您的数据集填充方法....

数据适配器

  // Assumes that connection is a valid SqlConnection object.
string queryString = 
  "SELECT CustomerID, CompanyName FROM dbo.Customers";
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);

DataSet customers = new DataSet();
adapter.Fill(customers, "Customers");
于 2011-05-04T13:56:49.760 回答