【发布时间】:2014-02-04 04:10:43
【问题描述】:
我有这样的代码
Global.dbCon.Open();
int idQuestion;
kalimatSql = kalimatSql;
Global.reader = Global.riyeder(kalimatSql);
if (Global.reader.HasRows) {
while (Global.reader.Read()) {
idQuestion = Convert.ToInt32(Global.reader.GetValue(0));
//messageBox.Show(idQuestion.ToString()); -->first message box
}
}
//messageBox.Show(idQuestion.ToString()); -->second message box
Global.dbCon.Close();
显示第一个消息框没有问题,但是如何显示第二个消息框
已编辑
我尝试让@rhughes 中的代码成为如下代码中的函数(类)
Global.dbCon.Open();
List<int> idQuestions = new List<int>();
Global.reader = Global.riyeder(kalimatSql);
if (Global.reader.HasRows) {
while (Global.reader.Read()) {
int idQuestion = Convert.ToInt32(Global.reader.GetValue(0));
idQuestions.Add(idQuestion);
}
}
Global.dbCon.Close();
foreach (int id in idQuestions) {
return id;
}
但这不起作用,因为并非所有代码路径都返回一个值...我想知道如何正确地做到这一点?
【问题讨论】:
-
什么是问题?
-
@Selman22 显示第二个消息框
-
你可以说你想在第二个消息框中显示什么!
-
@Selman22 他做到了 - //messageBox.Show(idQuestion.ToString()); -->第二个消息框
-
@rhughes 不清楚他想要什么。他想显示最后一个 idQuestion,还是所有带有循环的 idQuestions,或者同时使用一个消息框显示所有 idQuestions