Juh*_*jos 5 c# ienumerable visual-studio visual-studio-debugging
我想要有人帮忙。我想执行一个 MS SQL(SELECT 语句)。数据源连接建立起来,下面的源码都运行无误。但是,在阅读器对象中,结果视图是空白的。此错误消息是:展开结果视图将枚举 IEnumerabl。SELECT 命令被记录下来。我在 SQL 管理器应用程序上单独运行它并得到结果,语法是一个很好的 SQL 命令。我做错了什么?
// ********************** 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();
Run Code Online (Sandbox Code Playgroud)

这与 Visual Studio 调试有关。您正在尝试开放IEnumerable类型,它可以有各种内部实现。要浏览该集合,您必须按>左侧的符号。它会为您弹出枚举。但它也可以运行隐藏在其后面的不必要的代码。
在该财产扩大之前,它永远不会被展示。这不是List或Dictionary类型,您可以在其中访问其中的任何项目。IEnumerable必须首先枚举才能正确显示。
| 归档时间: |
|
| 查看次数: |
9379 次 |
| 最近记录: |