GridView is not picking up Empty Data object

lapEnlani

New Member
I have a gridview which is fed by a stored proc via standard n-tier structure that should trigger the emplty row object but it doesn't. Instead I get an exception "The IListSource does not contain any data source". If I run the query in SQL server Management Studion it returns an empty row. I suspect the issue is with the transact-sql, I'm using a PIVOR consrtuct and since I'm not that familiar how it works, I think that causes the issue. It was borrowed it from this blog and was modified by my predecesor.Does anyone has an idea what causes the issue? Here the code. Thanks!<asp:GridView ID="gvSystemRMRiskRpt" runat="server" AutoGenerateColumns="true" CellPadding="3" PageSize="25" BackColor="White" BorderColor="MidnightBlue" BorderStyle="Groove" BorderWidth="1px" CssClass="TextCompact" GridLines="Vertical" OnRowDataBound="gvSystemRMRiskRpt_OnDataBound" EmptyDataText="Your request has returned zero records" > <RowStyle BackColor="#EEEEEE" ForeColor="Black" /> <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="Gainsboro" /> <FooterStyle BackColor="#CCCCCC" ForeColor="Black" VerticalAlign="Top" /></asp:GridView>Code file:vSystemRpt.DataSource = Data.ByMonthYear(connectionManager,site,startDate[1],stopDate[1],interval/*,_dtCodes.ToString()*/);gvSystemRMRiskRpt.DataBind();Data Layer: public static DataSet ByMonthYear(ConnectionManager connectionManager, Guid site, string startDate, string stopDate, int interval) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "[dbo].[ByMonthYear_StoredProc]"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = connectionManager.GetSqlConnectionContext(); cmd.Transaction = connectionManager.GetSqlTransactionContext(); SqlParameter paramSiteGUID = new SqlParameter("@SiteGUID", SqlDbType.UniqueIdentifier); paramSiteGUID.Value = http://stackoverflow.com/questions/14388938/site; cmd.Parameters.Add(paramSiteGUID); SqlParameter paramStartDate = new SqlParameter("@StartDate", SqlDbType.VarChar); paramStartDate.Value = http://stackoverflow.com/questions/14388938/startDate; cmd.Parameters.Add(paramStartDate); SqlParameter paramStopDate = new SqlParameter("@StopDate", SqlDbType.VarChar); paramStopDate.Value = http://stackoverflow.com/questions/14388938/stopDate; cmd.Parameters.Add(paramStopDate); SqlParameter paramProcedureAction = new SqlParameter("@ProcedureAction", SqlDbType.Int); paramProcedureAction.Value = http://stackoverflow.com/questions/14388938/0; // From Primary Key cmd.Parameters.Add(paramProcedureAction); SqlParameter paramInterval = new SqlParameter("@Interval", SqlDbType.Int); paramInterval.Value = http://stackoverflow.com/questions/14388938/interval; cmd.Parameters.Add(paramInterval); SqlDataAdapter sqlDA = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sqlDA.Fill(ds); cmd.Dispose(); cmd = null; return ds; }and the actual stored proc:alter PROCEDURE [dbo].[ByMonthYear_StoredProc]@ProcedureAction int,@SiteGUID uniqueidentifier = null,@StartDate varchar(4),@StopDate varchar(4),@Interval intASDECLARE @cols NVARCHAR(2000)DECLARE @query NVARCHAR(4000)IF (@ProcedureAction = 0) -- From BEGIN SET NOCOUNT ON SET TRANSACTION ISOLATION LEVEL READ COMMITTED IF (@Interval = 1) -- Montly BEGIN SELECT @cols = STUFF(( SELECT DISTINCT TOP 100 PERCENT '],[' + cast(MonthYear as varchar(10)) FROM vByMonthYear where SiteGUID = @SiteGuid and [Year] BETWEEN '2005' AND '2010' ORDER BY '],[' + cast(MonthYear as varchar(10)) FOR XML PATH('') ), 1, 2, '') + ']' SET @query = N'SELECT EventType, ' + @cols +' FROM (SELECT MonthYear,EventType,Value,OrderBy FROM vRByMonthYear where SiteGUID = ' + CHAR(39) + CONVERT(nvarchar(36), @SiteGuid) + CHAR(39) + ' and Year BETWEEN 2005 AND 2010) p PIVOT ( Sum ([Value] ) FOR MonthYear IN ( '+ @cols +' ) ) AS pvt order by OrderBy' execute(@query) ENDENDJust to reiterate, if I run SELECT DISTINCT TOP 100 PERCENT '],[' + cast(MonthYear as varchar(10)) FROM vByMonthYear where SiteGUID = @SiteGuid and [Year] BETWEEN '2005' AND '2010' in the query window and I substitute the @SiteGuid with an actual value that I know has no record I get an empty row but in my app I get the exception. Thanks again!
 
Back
Top