这个代码显示了不可访问的代码,是我在这里遗漏了什么吗?我正在使用c#和ASP.NET。当我运行这个代码响应。重定向("上传Process.aspx ?QuizID=" + id + ");千万别到这儿来。
if (Page.IsValid)
{
string number = ddlNumber.SelectedValue.ToString();
string title = txtTitle.Text;
string level = txtLevel.Text;
string duration = txtDuration.Text;
Quiz m = new Quiz
{
NumberOfQuestion = int.Parse(number),
Title = title,
Level = char.Parse(level),
Duration = int.Parse(duration)
};
db.Quizs.InsertOnSubmit(m);
db.SubmitChanges();
string id ="";
var q = from Quiz in db.Quizs where Quiz.Title == title select Quiz;
foreach(var p in q)
{
id = p.QuizID.ToString();
}
for (int a = 0; 0 < int.Parse(number); a++)
{
Question o = new Question
{
QuizID = int.Parse(id)
};
db.Questions.InsertOnSubmit(o);
db.SubmitChanges();
}
Response.Redirect("Upload Process.aspx?QuizID=" + id + "");
}
注意number
在这个循环中从来没有改变过
for (int a = 0; 0 < int.Parse(number); a++)
{
Question o = new Question
{
QuizID = int.Parse(id)
};
db.Questions.InsertOnSubmit(o);
db.SubmitChanges();
}
如果0 < int.Parse(number)
在循环开始时为真,则在循环继续执行时它将继续为真
你确定不是
for (int a = 0; a < int.Parse(number); a++)
想想看,0什么时候会>= than number?