Reputation: 139
when i am executing the code i am getting the exception in frmtime is
System.IndexOutOfRangeException: Index was outside the bounds of the array
public IList<ExamSeatAllotmentEntity> GetAttendence1(string frmtime, string totime, DateTime date, int RoomNo)
{
List<ExamSeatAllotmentEntity> ObjTestList = new List<ExamSeatAllotmentEntity>();
//List<QuestionTypeEntity> ObjQTList = new List<QuestionTypeEntity>();
SqlParameter[] Parms = new SqlParameter[1];
Parms[0] = new SqlParameter("@RoomNo", SqlDbType.Int);
Parms[0].Value = RoomNo;
Parms[1] = new SqlParameter("@FromTime", SqlDbType.Time);
Parms[1].Value = frmtime;
Parms[2] = new SqlParameter("@Totime", SqlDbType.Time);
Parms[2].Value = totime;
Parms[3] = new SqlParameter("@Date", SqlDbType.DateTime);
Parms[3].Value = date;
DataSet dsTest = SqlHelper.ExecuteDataset(SqlHelper.connString, CommandType.StoredProcedure, SQL_PROC_GET_Attendence1, Parms);
if (dsTest != null && dsTest.Tables.Count == 1)
{
ObjTestList = (from test in dsTest.Tables[0].AsEnumerable()
select new ExamSeatAllotmentEntity()
{
// CourseID = test.Field<int>("CourseID"),
StudentId = test.Field<int>("StudentId"),
Fname = test.Field<string>("Fname"),
SeatNo = test.Field<string>("SeatNo"),
Attendence = test.Field<string>("Attendence")
}).ToList<ExamSeatAllotmentEntity>();
}
return ObjTestList;
}
Upvotes: 0
Views: 101
Reputation: 6731
Change
SqlParameter[] Parms = new SqlParameter[1];
to
SqlParameter[] Parms = new SqlParameter[4];
Upvotes: 1
Reputation: 887215
new SqlParameter[1]
You just made an array that can only hold one item.
Upvotes: 4
Reputation: 19871
This would be the problem:
SqlParameter[] Parms = new SqlParameter[1];
You are specifying a length of 1 element: Parms[0]
Correct the size of the array to allow 4 elements:
SqlParameter[] Parms = new SqlParameter[4];
In case you want to add more parameters, you might want to create a list and then transform via ToArray()
.
Upvotes: 1