Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当我执行代码时,我得到一个System.IndexOutOfRangeException_C#_Asp.net - Fatal编程技术网

C# 当我执行代码时,我得到一个System.IndexOutOfRangeException

C# 当我执行代码时,我得到一个System.IndexOutOfRangeException,c#,asp.net,C#,Asp.net,当我执行代码时,我在frmtime中得到的异常是 System.IndexOutOfRangeException:索引超出了 排列 public IList getAttentidence1(字符串frmtime、字符串totime、日期时间日期、int RoomNo) { List ObjTestList=新列表(); //List ObjQTList=新列表(); SqlParameter[]Parms=新的SqlParameter[1]; Parms[0]=新的SqlParameter(“

当我执行代码时,我在frmtime中得到的异常是

System.IndexOutOfRangeException:索引超出了 排列

public IList getAttentidence1(字符串frmtime、字符串totime、日期时间日期、int RoomNo)
{
List ObjTestList=新列表();
//List ObjQTList=新列表();
SqlParameter[]Parms=新的SqlParameter[1];
Parms[0]=新的SqlParameter(“@RoomNo”,SqlDbType.Int);
参数[0]。值=房间号;
Parms[1]=新的SqlParameter(“@FromTime”,SqlDbType.Time);
参数[1]。值=frmtime;
Parms[2]=新的SqlParameter(“@Totime”,SqlDbType.Time);
参数[2]。值=总时间;
Parms[3]=新的SqlParameter(“@Date”,SqlDbType.DateTime);
参数[3]。值=日期;
数据集dsTest=SqlHelper.ExecuteDataset(SqlHelper.connString,CommandType.StoredProcedure,SQL_PROC_GET_Attendence1,Parms);
if(dsTest!=null&&dsTest.Tables.Count==1)
{
ObjTestList=(来自dsTest.Tables[0]中的测试)。AsEnumerable()
选择新的ExamCatalotEntity()
{
//CourseID=测试字段(“CourseID”),
StudentId=测试字段(“StudentId”),
Fname=测试字段(“Fname”),
SeatNo=测试字段(“SeatNo”),
注意力=测试字段(“注意力”)
}).ToList();
}
返回ObjTestList;
}

这就是问题所在:

SqlParameter[] Parms = new SqlParameter[1];
您指定的长度为1个元素:
Parms[0]

更正数组的大小以允许4个元素:

SqlParameter[] Parms = new SqlParameter[4];
SqlParameter[] Parms = new SqlParameter[4];

如果要添加更多参数,可能需要创建一个列表,然后通过
ToArray()

进行转换,这就是问题所在:

SqlParameter[] Parms = new SqlParameter[1];
您指定的长度为1个元素:
Parms[0]

更正数组的大小以允许4个元素:

SqlParameter[] Parms = new SqlParameter[4];
SqlParameter[] Parms = new SqlParameter[4];
如果要添加更多参数,可能需要创建一个列表,然后通过
ToArray()
进行转换

您刚刚创建了一个只能容纳一项的数组

您刚刚创建了一个只能容纳一项的数组。

更改

SqlParameter[] Parms = new SqlParameter[1];

改变