我的代码的第一部分在数组列表中添加项目。
当我稍后尝试使用 for 循环访问其内容时,arraylist 被清除并且不返回任何值。
*CODE/FLOW 我首先想知道程序下有哪些事件。我单击搜索按钮,然后从数据库中读取并将其结果放入数组中。
while (dr.Read())
{
string eventID = Convert.ToString(dr["Event ID"]);
programEvents.Add(eventID);
}
由于事件已经显示,然后我输入人名以将它们注册到事件下
for (int ctr = 0; ctr < spPeoplePicker.ResolvedEntities.Count; ctr++)
{
PickerEntity selectedEntity = (PickerEntity)spPeoplePicker.ResolvedEntities[ctr];
//get the email of the person added
//use this email as search tool for Peoplesoft database
string entityEmail = Convert.ToString(selectedEntity.EntityData["Email"]);
//string email = Convert.ToString(selectedEntity.EntityData["Title"]);
//line below can get display name of entity
PickerEntity pe = (PickerEntity)spPeoplePicker.ResolvedEntities[ctr];
for (int evectr = 0; evectr <= programEvents.Count; evectr++)
{
这是失败的地方。
paramID = programEvents[evectr];
#region getEventDetails
ProgramManagement.Conn connect = new ProgramManagement.Conn();
SqlConnection conn = new SqlConnection(@connect.getConnString());
conn.Open();
SqlCommand stmnt = conn.CreateCommand();
stmnt.CommandText = "SELECT * FROM [TrainingAndScheduling].[dbo].[trainersView]" +
" WHERE EventID='" + paramID + "'"; ;
SqlDataReader thisReader = stmnt.ExecuteReader();
if (thisReader.HasRows)
{
thisReader.Read();
eveName = Convert.ToString(thisReader["CourseName"]);
eveStart = Convert.ToString(thisReader["StartDate"]);
eveEnd = Convert.ToString(thisReader["EndDate"]);
eveVenue = Convert.ToString(thisReader["RoomID"]);
}
else
{ }
thisReader.Close();
conn.Close();
#endregion
#region registration for a single event
ProgramManagement.Registration register = new ProgramManagement.Registration();
if (!register.register(entityEmail, paramID))
{
//this block is executed if user is not registered
errorAdding = errorAdding + "<br/>" + "Engineer: " +
pe.DisplayText + " was not registered.";
}
else
{
ProgramManagement.Email sendemail = new ProgramManagement.Email();
sendemail.sendNotification(entityEmail, pe.DisplayText, eveName, eveStart, eveEnd, eveVenue, paramID);
}
#endregion
}
}