错误:
System.IndexOutOfRangeException 在 System.Data.ProviderBase.FieldNameLookup.GetOrdinal(字符串fieldName) 在System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)在 System.Data.SqlClient.SqlDataReader.get_Item(字符串名称)位于
我更改了存储过程以将两个新列添加到结果中,该存储过程本身似乎正常工作,但是当我将新列添加到m = 8
n = 73
multiple <- function(n, m){
# your suggested solution #
}
时遇到此错误
型号
SQlDataReader
我的方法
public class StudentRecordFull : StudentRecord
{
public double CreditProgress { get; set; }
public string EnrollmentStatus { get; set; }
public int IsEnrolled { get; set; }
public string YRQLastAttended { get; set; }
public int Mandatory { get; set; }
public double GPA { get; set; }
public string TotalPrint { get; set; }
public int Balance { get; set; }
}
助手
public StudentRecordFull GetStudent(int sid)
{
StudentRecordFull s = new StudentRecordFull();
using (SqlConnection myConnection = new SqlConnection(ProductionDataConnString))
{
SqlCommand myCommand = new SqlCommand("usp_GetStudent", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter SIDParameter = myCommand.Parameters.Add("SID", SqlDbType.Char, 9);
SIDParameter.Value = sid;
myConnection.Open();
using (SqlDataReader oReader = myCommand.ExecuteReader())
{
while (oReader.Read())
{
s.SID = SafeGetString(oReader, "SID");
s.FirstName = SafeGetString(oReader, "FirstName");
s.LastName = SafeGetString(oReader, "LastName");
s.AdvisorName = SafeGetString(oReader, "Advisor");
s.AdvisorSID = SafeGetString(oReader, "AdvisorSID");
s.PathwayName = SafeGetString(oReader, "PathwayName");
s.PathwayID = SafeGetInt(oReader, "PathwayId");
s.SubPathwayID = SafeGetInt(oReader, "SubPathwayId");
s.SubPathwayName = SafeGetString(oReader,
"SubPathwayName");
//s.TotalPrint = SafeGetString(oReader, "ploplo");
s.Credits = SafeGetInt(oReader, "CreditsEarned");
s.Phone = SafeGetString(oReader, "DaytimePhone");
s.DOB = SafeGetString(oReader, "DOB");
s.Address = SafeGetString(oReader, "Address");
s.City = SafeGetString(oReader, "City");
s.State = SafeGetString(oReader, "State");
s.Zip = SafeGetString(oReader, "Zip");
s.Email = SafeGetString(oReader, "Email");
s.CreditProgress = SafeGetDouble(oReader,
"CreditProgress");
s.EnrollmentStatus = SafeGetString(oReader,
"EnrollmentStatus");
s.IsEnrolled = SafeGetInt(oReader, "IsEnrolled");
s.YRQLastAttended = SafeGetString(oReader,
"YRQLastAttended");
s.Mandatory = SafeGetInt(oReader, "Mandatory");
s.GPA = SafeGetDouble(oReader, "GPA");
s.Balance = SafeGetInt(oReader, "Balance");
//s.TotalPrint = SafeGetString(oReader, "TotalPrint");
}
myConnection.Close();
}
}
return s;
}
如果我删除新列,那么一切正常,就像无法读取那些列。
有什么主意吗?