Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding the Results View will enumerate the IEnumerable

I want someone to help. I want to execute a MS SQL (SELECT statement). The data source connection builds up, all under the source code below runs without error. However, in the reader object, the Result view is blank. This error message is: Expanding the Results View will enumerate the IEnumerabl. The SELECT command is noted. I run it separately on an SQL manager application and have a result, syntax is a good SQL command. What do I do wrong?

// **********************  SQL Connect building   ****************************
SqlConnection myMSSQLConn;
SqlCommand SQL_command = new SqlCommand(); 
SqlDataReader reader;

try //MS SQL connect building
{
    myMSSQLConn = new SqlConnection(AccInstance.SQL_myConnection_string);
}
catch (Exception ex)
{
    AccInstance._MasterErrorText = "Connect error" + ex;
    AccInstance.Messages("39", "");
    return 0;
}

// "SELECT TOP 1 CITYS.V_NUM FROM dbo.CITYS ORDER BY CITYS.V_NUM DESC"
SQL_command.CommandText = MSSQLOperation_command; 
SQL_command.CommandType = CommandType.Text;
SQL_command.Connection = myMSSQLConn;
myMSSQLConn.Open();
reader = SQL_command.ExecuteReader();

while (reader.Read())
{
    MessageBox.Show(reader.GetValue(0)
               + " - " + reader.GetValue(1)
               + " - " + reader.GetValue(2));
}
reader.Close();
SQL_command.Dispose();
myMSSQLConn.Close();

enter image description here

like image 683
Juhász Lajos Avatar asked Oct 17 '22 18:10

Juhász Lajos


1 Answers

This is related to Visual Studio debugging. You are trying to open IEnumerable type, which can have various inner implementations. To run throught the collection, You have to press the > symbol on the left. It will pop-out the enumeration for you. But it can also run unnecessary code hidden behind it.

Until the property is expanded, it won't ever be shown. This is not List or Dictionary type, where You can access any item inside. IEnumerable must be enumerated first to be shown properly.

like image 191
Tatranskymedved Avatar answered Nov 15 '22 08:11

Tatranskymedved