none
ResultView Enuramation yielded no results RRS feed

  • Question

  • I raised this as a bug last year through VS Community 2017 feedback but it never got resolved, only got to triage recently before being discarded due lack of severity.  I am running a query on a sql server table and despite the results showing a field count of 1, ResultsView displays "Enumeration yielded no results".  This query is returning true or false.  No result would indicate a field count of 0.  Anyone have any ideas?

    My theory is that there is a problem (bug) with the ResultsView accessing the SqlDataReader in order to display the results, I can't come up with any other logical explanation.  There is data, field count 1, its just having a problem reading and displaying it.  

    Friday, August 16, 2019 7:45 PM

All replies

  • Hi RichardDunneBSc,

    Sorry for delay in reply.

    Based on your description, you need to specify that you are using a stored procedure, please add the below sample in your code:

    using System.Data;
    
    SqlCommand command = new SqlCommand("GetCustomers", conn);
    command.CommandType = CommandType.StoredProcedure;

    Please refer more here: https://stackoverflow.com/a/49534510

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, August 19, 2019 7:19 AM
  • Thanks for the reply.  It seems that IEnumerable is not very reliable with certain data types, from my observation.  The "date" field was of type DateTime, Enumerate yielded no results. Changed it to varchar, then to date, it seems to prefer date, working like a charm (for now).  
    Monday, August 19, 2019 9:09 AM
  • Hi RichardDunneBSc,

    Thank you for reply.

    I have tried Enumerate with DateTime via referring the DOC: IEnumerable Interface  , it could show results, please refer the below screenshot:

    But I use local data instead of sql server. Please check if local data could work on your side.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, August 20, 2019 9:44 AM
  • I'm getting an on that first line date[].  What library are you using?
    Tuesday, August 20, 2019 10:00 AM
  • Hi RichardDunneBSc,

    I test it in the new console app(.net framework), and I don't add extra library. I just add "using System.Collections;" namespace. And then I remove all default dlls, it could also work.


    using System;
    using System.Collections;
    
    public class date
    {
        public date(DateTime pre, DateTime aft)
        {
            this.pretime = pre;
            this.afttime = aft;
        }
    
        public DateTime pretime;
        public DateTime afttime;
    }
    
    public class Datetimetest : IEnumerable
    {
        private date[] _time;
        public Datetimetest(date[] pArray)
        {
            _time = new date[pArray.Length];
    
            for (int i = 0; i < pArray.Length; i++)
            {
                _time[i] = pArray[i];
            }
        }
    
        IEnumerator IEnumerable.GetEnumerator()
        {
            return (IEnumerator)GetEnumerator();
        }
    
        public TimeEnum GetEnumerator()
        {
            return new TimeEnum(_time);
        }
    }
    
    public class TimeEnum : IEnumerator
    {
        public date[] _time;
    
        int position = -1;
    
        public TimeEnum(date[] list)
        {
            _time = list;
        }
    
        public bool MoveNext()
        {
            position++;
            return (position < _time.Length);
        }
    
        public void Reset()
        {
            position = -1;
        }
    
        object IEnumerator.Current
        {
            get
            {
                return Current;
            }
        }
    
        public date Current
        {
            get
            {
                try
                {
                    return _time[position];
                }
                catch (IndexOutOfRangeException)
                {
                    throw new InvalidOperationException();
                }
            }
        }
    }
    
    class App
    {
        static void Main()
        {
            date[] dateArray = new date[3]
            {
                new date(DateTime.Parse("5/1/2008 8:30:52 AM",
                              System.Globalization.CultureInfo.InvariantCulture), DateTime.Parse("6/1/2008 8:30:52 AM",
                              System.Globalization.CultureInfo.InvariantCulture)),
                new date(DateTime.Parse("7/1/2008 8:30:52 AM",
                              System.Globalization.CultureInfo.InvariantCulture), DateTime.Parse("8/1/2008 8:30:52 AM",
                              System.Globalization.CultureInfo.InvariantCulture)),
                new date(DateTime.Parse("9/1/2008 8:30:52 AM",
                              System.Globalization.CultureInfo.InvariantCulture), DateTime.Parse("10/1/2008 8:30:52 AM",
                              System.Globalization.CultureInfo.InvariantCulture)),
            };
    
            Datetimetest dateList = new Datetimetest(dateArray);
            foreach (date p in dateList)
                Console.WriteLine(p.pretime + " " + p.afttime);
    
        }
    }
    

    Maybe you could create a new project and refer the above document to test if it could work on your side. 

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, August 20, 2019 10:29 AM
  • I am displaying the data from an sql table in a DataGridView.  After completing the the query, I checked the ResultsView and was able to see all the data in SqlDataReader (for a change).  Waited about 10 seconds or so, had another look, Enumeration yielded no results.  This looks like IEnumerable is timing out, if it wasn't, it wouldn't matter how long afterwards I looked again, I should still be able to see the data. 
    Tuesday, August 20, 2019 4:50 PM
  • Hi RichardDunneBSc,

    Thank you for reply.

    Based on your description, it seems that the sql connection severs automatically. Please try to set "SqlConnectiontimeout" to extend time. Please refer the below sample:

    private static void OpenSqlConnection()
    {
        string connectionString = GetConnectionString();
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            connection.Open();
            Console.WriteLine("State: {0}", connection.State);
            Console.WriteLine("ConnectionTimeout: {0}",
                connection.ConnectionTimeout);
        }
    }
    
    static private string GetConnectionString()
    {
        // To avoid storing the connection string in your code, 
        // you can retrieve it from a configuration file, using the 
        // System.Configuration.ConfigurationSettings.AppSettings property 
        return "Data Source=(local);Initial Catalog=AdventureWorks;"
            + "Integrated Security=SSPI;Connection Timeout=50";         //the unit is second
    }

    Please refer more here: SqlConnection.ConnectionTimeout Property

    Best Regards,

    Dylan




    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, August 22, 2019 2:36 AM