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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With