BLL 、Model、IDAL、SqlServerDAL下面都有个文件夹School,school文件夹下面都有PraxisInfro.cs
aspx.cs代码:里面的PraxisId就是我的主键,自增的
/*从PraxisInfro表中读取此用户的PraxisId,,此时取出后一次插入时主键值*/
BLL.School.PraxisInfro bll1 = new BLL.School.PraxisInfro();
Model.School.PraxisInfro model1 = bll1.GetLastid();
PraxisId = model.PraxisId.ToString();BLL重的代码:
namespace BLL.School
{
public class PraxisInfro
{ public Model.School.PraxisInfro GetLastid()
{
return DALFactory.DataAccess.PraxisInfro.GetLastid();
}
}
}IDAL重的代码:namespace IDAL.School
{
public interface IPraxisInfro
{
Model.School.PraxisInfro GetLastid(); }
}最关键的SqlServerDAL代码:
public Model.School.PraxisInfro GetLastid()
{ SqlDataReader dr = SqlServerHelper.ExecuteReader (CommandType.StoredProcedure, "PraxisInfro_GetLastid");
Model.School.PraxisInfro model = new Model.School.PraxisInfro(); while (dr.Read())
{
model.PraxisId= (int)dr["PraxisId"];
model.Profession = dr["Profession"].ToString();
model.Degree = dr["Degree"].ToString();
model.ForeignLanguage = dr["ForeignLanguage"].ToString();
model.MaleStudents = dr["MaleStudents"].ToString();
model.FemaleStudents = dr["FemaleStudents"].ToString();
model.WorkYear = dr["WorkYear"].ToString();
model.WorkMonth = dr["WorkMonth"].ToString();
model.TimeRange = dr["TimeRange"].ToString();
model.Request = dr["Request"].ToString();
model.Introduction = dr["Introduction"].ToString();
}
dr.Close(); return model;
}
他怎么提示错误:
PraxisId
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: PraxisId源错误:
行 110: {
行 111:
行 112: model.PraxisId= (int)dr["PraxisId"];行 113: model.Profession = dr["Profession"].ToString();
行 114: model.Degree = dr["Degree"].ToString();
aspx.cs代码:里面的PraxisId就是我的主键,自增的
/*从PraxisInfro表中读取此用户的PraxisId,,此时取出后一次插入时主键值*/
BLL.School.PraxisInfro bll1 = new BLL.School.PraxisInfro();
Model.School.PraxisInfro model1 = bll1.GetLastid();
PraxisId = model.PraxisId.ToString();BLL重的代码:
namespace BLL.School
{
public class PraxisInfro
{ public Model.School.PraxisInfro GetLastid()
{
return DALFactory.DataAccess.PraxisInfro.GetLastid();
}
}
}IDAL重的代码:namespace IDAL.School
{
public interface IPraxisInfro
{
Model.School.PraxisInfro GetLastid(); }
}最关键的SqlServerDAL代码:
public Model.School.PraxisInfro GetLastid()
{ SqlDataReader dr = SqlServerHelper.ExecuteReader (CommandType.StoredProcedure, "PraxisInfro_GetLastid");
Model.School.PraxisInfro model = new Model.School.PraxisInfro(); while (dr.Read())
{
model.PraxisId= (int)dr["PraxisId"];
model.Profession = dr["Profession"].ToString();
model.Degree = dr["Degree"].ToString();
model.ForeignLanguage = dr["ForeignLanguage"].ToString();
model.MaleStudents = dr["MaleStudents"].ToString();
model.FemaleStudents = dr["FemaleStudents"].ToString();
model.WorkYear = dr["WorkYear"].ToString();
model.WorkMonth = dr["WorkMonth"].ToString();
model.TimeRange = dr["TimeRange"].ToString();
model.Request = dr["Request"].ToString();
model.Introduction = dr["Introduction"].ToString();
}
dr.Close(); return model;
}
他怎么提示错误:
PraxisId
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: PraxisId源错误:
行 110: {
行 111:
行 112: model.PraxisId= (int)dr["PraxisId"];行 113: model.Profession = dr["Profession"].ToString();
行 114: model.Degree = dr["Degree"].ToString();
/*功能:取出最后插入的主键值 */
CREATE Procedure [dbo].[PraxisInfro_GetLastid]AS
select IDENT_CURRENT(' PraxisInfro')
GO
应该在
while(dr.read())
前加个判断
if(dr!=null)
{
while(dr.read())
{
//your code
}
}
model.Degree = dr["Degree"].ToString();
model.ForeignLanguage = dr["ForeignLanguage"].ToString();
model.MaleStudents = dr["MaleStudents"].ToString();
model.FemaleStudents = dr["FemaleStudents"].ToString();
model.WorkYear = dr["WorkYear"].ToString();
model.WorkMonth = dr["WorkMonth"].ToString();
model.TimeRange = dr["TimeRange"].ToString();
model.Request = dr["Request"].ToString();
model.Introduction = dr["Introduction"].ToString(); 这么多东西呢?肯定是读不出来的,你可以把这个注释掉以后再试试,或者注释掉第一句试试