Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:57:41+00:00 2026-06-17T17:57:41+00:00

I have a gridview which is fed by a stored proc via standard n-tier

  • 0

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.

<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:

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Guid site = new Guid(ddlSites.SelectedValue);
        int interval = Convert.ToInt16(ddlIntervals.SelectedValue);
        string[] startDate = tbStartDate.Text.Split('/');  // 01-2001
        string[] stopDate = tbEndDate.Text.Split('/');     // 12/2002

        gvSystemRMRiskRpt.DataSource = Data.ByMonthYear(connectionManager,site,startDate[1],stopDate[1],interval);
        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 = site;
        cmd.Parameters.Add(paramSiteGUID);

        SqlParameter paramStartDate = new SqlParameter("@StartDate", SqlDbType.VarChar);
        paramStartDate.Value = startDate;
        cmd.Parameters.Add(paramStartDate);

        SqlParameter paramStopDate = new SqlParameter("@StopDate", SqlDbType.VarChar);
        paramStopDate.Value = stopDate;
        cmd.Parameters.Add(paramStopDate);

        SqlParameter paramProcedureAction = new SqlParameter("@ProcedureAction", SqlDbType.Int);
        paramProcedureAction.Value = 0; // From Primary Key
        cmd.Parameters.Add(paramProcedureAction);

        SqlParameter paramInterval = new SqlParameter("@Interval", SqlDbType.Int);
        paramInterval.Value = 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 int
AS

DECLARE @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)
    END
END

Just 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:57:42+00:00Added an answer on June 17, 2026 at 5:57 pm

    I suspect this is what happened but am not 100% certain. The adapter

      SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      sqlDA.Fill(ds);
    

    was being filled with a row of no data and so the dataset that was returned was not treated as empty – not sure why. I suspect the weird SQL Pivot was returning some reference or white space.

    Anyway, I had changed the method to return a DataTable instead of DataSet and droped the entire SqlDataAdapter and instead used a SqlReader which worked. Probably saved some 1 milisecond of overhead in the process.

    using (SqlDataReader _reader = cmd.ExecuteReader())
    {
         DataTable dt = new DataTable();
         dt.Load(_reader);
         cmd.Dispose();
         return dt;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView which you can click on a row and it should
I Have a gridview which has a row that contains LinkButtons that were added
I have a GridView in which each row has a custom view. The grid
I have a GridView to which I bind a dataTable that I manually created.
For example, Lets say that I have a gridview column which has important controls,
I have a GridView which has a RowCommand event that opens a modalpopupextender on
I have a gridview which displays data for all employees and their images (stored
I have a gridview which should allow rows to be in edit mode. this
I have a gridview which is pulling it data from a stored procedure. In
I have gridview which contains 60 rows and each row has 4 radiobutton option

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.