还是执行web页面时候出现的错误:
“/Web”应用程序中的服务器错误。未将对象引用设置到对象的实例。说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 43: {
行 44: Console.Write(e.Message);
行 45: throw e;
行 46: }
行 47: }源文件: D:\HR\HRDAL\ResumeService.cs 行: 45 附ResumeService.cs代码(字数限制,省去一部分用不到的):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HRModels;
using System.Data.SqlClient;namespace HRDAL
{
public static partial class ResumeService
{
//添加简历
public static Resume AddResume(Resume resume)
{
string sql=
"INSERT Resume (userId, name, sex, identityNo, birthday, stature, degree, school, marriage, occupation, career, specialty, email, phone, address)"+"VALUES(@userId, @name, @sex, @identityNo, @birthday, @stature, @degree, @school, @marriage, @occupation, @career, @specialty, @email, @phone, @address)";
sql +="; SELECT @@IDENTITY";
try
{
SqlParameter[] para=new SqlParameter[]
{
new SqlParameter("@userId",resume.User.UserId),//FK
new SqlParameter("@name",resume.Name),
new SqlParameter("@sex",resume.Sex),
new SqlParameter("@identityNo",resume.IdentityNo),
new SqlParameter("@birthdy",resume.Birthday),
new SqlParameter("@stature",resume.Stature),
new SqlParameter("@degree",resume.Degree),
new SqlParameter("@school",resume.School),
new SqlParameter("@marriage",resume.Marriage),
new SqlParameter("@occupation",resume.Occupation),
new SqlParameter("@career",resume.Career),
new SqlParameter("@specialty",resume.Specialty),
new SqlParameter("@email",resume.Email),
new SqlParameter("@phone",resume.Phone),
new SqlParameter("@address",resume.Address)
};
int newId=DBhelper.GetScalar(sql, para);
return GetResumeByResumeId(newId);
}
catch(Exception e)
{
Console.Write(e.Message);
throw e;
}
}
//修改简历
public static void ModifyResume(Resume resume)
{
string sql =
"update Resume" +
"set" +
"userId=@userId," +//FK
"name=@name," +
"sex=@sex," +
"identityNo=@identityNo," +
"birthday=@birthday," +
"stature=@stature," +
"degree=@degree," +
"school=@school," +
"marriage=@marriage," +
"occupation=@occupation," +
"career=@career," +
"specialty=@specialty," +
"email=@email," +
"phone=@phone," +
"address=@address," +
"where resumeId=@resumeId";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@resumeId",resume.ResumeId),
new SqlParameter("@userId",resume.User.UserId),//FK
new SqlParameter("@name",resume.Name),
new SqlParameter("@sex",resume.Sex),
new SqlParameter("@identityNo",resume.IdentityNo),
new SqlParameter("@birthdy",resume.Birthday),
new SqlParameter("@stature",resume.Stature),
new SqlParameter("@degree",resume.Degree),
new SqlParameter("@school",resume.School),
new SqlParameter("@marriage",resume.Marriage),
new SqlParameter("@occupation",resume.Occupation),
new SqlParameter("@career",resume.Career),
new SqlParameter("@specialty",resume.Specialty),
new SqlParameter("@email",resume.Email),
new SqlParameter("@phone",resume.Phone),
new SqlParameter("@address",resume.Address),
};
DBhelper.ExecuteCommand(sql,para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//获取所有简历
public static IList<Resume> GetAllResumes()
{
string sqlAll = "select * from Resume";
return GetResumeBySql(sqlAll);
}
//根据resumeId获取简历
public static Resume GetResumeByResumeId(int resumeId)
{
string sql = "SELECT * FROM Resume WHERE ResumeId=@ResumeId";
int userId;
try
{
SqlDataReader reader = DBhelper.GetReader(sql, new SqlParameter("@ResumeId", resumeId));
if (reader.Read())
{
Resume resume = new Resume();
resume.ResumeId = (int)reader["resumeId"];
resume.Name = (string)reader["name"];
resume.Sex = (string)reader["sex"];
resume.IdentityNo = (string)reader["identityNo"];
resume.Birthday = (DateTime)reader["birthday"];
resume.Stature = (string)reader["stature"];
resume.Degree = (string)reader["degree"];
resume.School = (string)reader["school"];
resume.Marriage = (string)reader["marriage"];
resume.Occupation = (string)reader["occupation"];
resume.Career = (string)reader["career"];
resume.Specialty = (string)reader["specialty"];
resume.Email = (string)reader["email"];
resume.Phone = (string)reader["phone"];
resume.Address = (string)reader["address"];
userId = (int)reader["userId"];//FK
reader.Close();
resume.User = UserService.GetUserByUserId(userId);
return resume;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//根据userId获取简历
public static Resume GetResumeByUserId(int userId)
{
string sql = "select * from Resume where userId=@UserId";
try
{
SqlDataReader reader = DBhelper.GetReader(sql,new SqlParameter("@userId",userId));
if (reader.Read())
{
Resume resume = new Resume();
resume.ResumeId = (int)reader["resumeId"];
resume.Name = (string)reader["name"];
resume.Sex = (string)reader["sex"];
resume.IdentityNo = (string)reader["identityNo"];
resume.Birthday = (DateTime)reader["birthday"];
resume.Stature = (string)reader["stature"];
resume.Degree = (string)reader["degree"];
resume.School = (string)reader["school"];
resume.Marriage = (string)reader["marriage"];
resume.Occupation = (string)reader["occupation"];
resume.Career = (string)reader["career"];
resume.Specialty = (string)reader["specialty"];
resume.Email = (string)reader["email"];
resume.Phone = (string)reader["phone"];
resume.Address = (string)reader["address"];
reader.Close();
resume.User = UserService.GetUserByUserId(userId);
return resume;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
}
}
还有一个问题:为什么我的页面用detailsview控件绑定的headertext显示出来的文字都是竖向排列的:
姓
名
性
别
这个方式的呢?设置了headstyle 的width也是无法改变,有什么办法可以让他横向排列吗?
谢谢大家了先,论坛大神很多,受益很多,在此谢谢先前帮我的大神!!!ASP.NETSQL对象Web
“/Web”应用程序中的服务器错误。未将对象引用设置到对象的实例。说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 43: {
行 44: Console.Write(e.Message);
行 45: throw e;
行 46: }
行 47: }源文件: D:\HR\HRDAL\ResumeService.cs 行: 45 附ResumeService.cs代码(字数限制,省去一部分用不到的):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HRModels;
using System.Data.SqlClient;namespace HRDAL
{
public static partial class ResumeService
{
//添加简历
public static Resume AddResume(Resume resume)
{
string sql=
"INSERT Resume (userId, name, sex, identityNo, birthday, stature, degree, school, marriage, occupation, career, specialty, email, phone, address)"+"VALUES(@userId, @name, @sex, @identityNo, @birthday, @stature, @degree, @school, @marriage, @occupation, @career, @specialty, @email, @phone, @address)";
sql +="; SELECT @@IDENTITY";
try
{
SqlParameter[] para=new SqlParameter[]
{
new SqlParameter("@userId",resume.User.UserId),//FK
new SqlParameter("@name",resume.Name),
new SqlParameter("@sex",resume.Sex),
new SqlParameter("@identityNo",resume.IdentityNo),
new SqlParameter("@birthdy",resume.Birthday),
new SqlParameter("@stature",resume.Stature),
new SqlParameter("@degree",resume.Degree),
new SqlParameter("@school",resume.School),
new SqlParameter("@marriage",resume.Marriage),
new SqlParameter("@occupation",resume.Occupation),
new SqlParameter("@career",resume.Career),
new SqlParameter("@specialty",resume.Specialty),
new SqlParameter("@email",resume.Email),
new SqlParameter("@phone",resume.Phone),
new SqlParameter("@address",resume.Address)
};
int newId=DBhelper.GetScalar(sql, para);
return GetResumeByResumeId(newId);
}
catch(Exception e)
{
Console.Write(e.Message);
throw e;
}
}
//修改简历
public static void ModifyResume(Resume resume)
{
string sql =
"update Resume" +
"set" +
"userId=@userId," +//FK
"name=@name," +
"sex=@sex," +
"identityNo=@identityNo," +
"birthday=@birthday," +
"stature=@stature," +
"degree=@degree," +
"school=@school," +
"marriage=@marriage," +
"occupation=@occupation," +
"career=@career," +
"specialty=@specialty," +
"email=@email," +
"phone=@phone," +
"address=@address," +
"where resumeId=@resumeId";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@resumeId",resume.ResumeId),
new SqlParameter("@userId",resume.User.UserId),//FK
new SqlParameter("@name",resume.Name),
new SqlParameter("@sex",resume.Sex),
new SqlParameter("@identityNo",resume.IdentityNo),
new SqlParameter("@birthdy",resume.Birthday),
new SqlParameter("@stature",resume.Stature),
new SqlParameter("@degree",resume.Degree),
new SqlParameter("@school",resume.School),
new SqlParameter("@marriage",resume.Marriage),
new SqlParameter("@occupation",resume.Occupation),
new SqlParameter("@career",resume.Career),
new SqlParameter("@specialty",resume.Specialty),
new SqlParameter("@email",resume.Email),
new SqlParameter("@phone",resume.Phone),
new SqlParameter("@address",resume.Address),
};
DBhelper.ExecuteCommand(sql,para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//获取所有简历
public static IList<Resume> GetAllResumes()
{
string sqlAll = "select * from Resume";
return GetResumeBySql(sqlAll);
}
//根据resumeId获取简历
public static Resume GetResumeByResumeId(int resumeId)
{
string sql = "SELECT * FROM Resume WHERE ResumeId=@ResumeId";
int userId;
try
{
SqlDataReader reader = DBhelper.GetReader(sql, new SqlParameter("@ResumeId", resumeId));
if (reader.Read())
{
Resume resume = new Resume();
resume.ResumeId = (int)reader["resumeId"];
resume.Name = (string)reader["name"];
resume.Sex = (string)reader["sex"];
resume.IdentityNo = (string)reader["identityNo"];
resume.Birthday = (DateTime)reader["birthday"];
resume.Stature = (string)reader["stature"];
resume.Degree = (string)reader["degree"];
resume.School = (string)reader["school"];
resume.Marriage = (string)reader["marriage"];
resume.Occupation = (string)reader["occupation"];
resume.Career = (string)reader["career"];
resume.Specialty = (string)reader["specialty"];
resume.Email = (string)reader["email"];
resume.Phone = (string)reader["phone"];
resume.Address = (string)reader["address"];
userId = (int)reader["userId"];//FK
reader.Close();
resume.User = UserService.GetUserByUserId(userId);
return resume;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//根据userId获取简历
public static Resume GetResumeByUserId(int userId)
{
string sql = "select * from Resume where userId=@UserId";
try
{
SqlDataReader reader = DBhelper.GetReader(sql,new SqlParameter("@userId",userId));
if (reader.Read())
{
Resume resume = new Resume();
resume.ResumeId = (int)reader["resumeId"];
resume.Name = (string)reader["name"];
resume.Sex = (string)reader["sex"];
resume.IdentityNo = (string)reader["identityNo"];
resume.Birthday = (DateTime)reader["birthday"];
resume.Stature = (string)reader["stature"];
resume.Degree = (string)reader["degree"];
resume.School = (string)reader["school"];
resume.Marriage = (string)reader["marriage"];
resume.Occupation = (string)reader["occupation"];
resume.Career = (string)reader["career"];
resume.Specialty = (string)reader["specialty"];
resume.Email = (string)reader["email"];
resume.Phone = (string)reader["phone"];
resume.Address = (string)reader["address"];
reader.Close();
resume.User = UserService.GetUserByUserId(userId);
return resume;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
}
}
还有一个问题:为什么我的页面用detailsview控件绑定的headertext显示出来的文字都是竖向排列的:
姓
名
性
别
这个方式的呢?设置了headstyle 的width也是无法改变,有什么办法可以让他横向排列吗?
谢谢大家了先,论坛大神很多,受益很多,在此谢谢先前帮我的大神!!!ASP.NETSQL对象Web
解决方案 »
- 无法将类型为“System.Object[]”的对象强制转换为类型“System.Web.UI.WebControls.Xml”。
- 试水.net制作的网页系统,在线帮助文档碰壁求解答
- RadioButtonList 和TextBox的联动问题..........
- 在线编辑器入库后再出库怎么截取
- GridView嵌套的问题
- 我的程序在很多台服务器上都没有问题,就是正式服务器上不行。
- 在外网上运行asp.net程序出错!
- 请问如何用vb.net语言is判断object对象是否为linkbutton类型.
- 我遇到这样的问题:以前调试用了Asp Net Web Matrixl软件来运用ASPNET程序....
- 关于client操作的问题(各位高手帮帮忙啊)
- 弱弱的问一句 我怎么找不到 IIS 文件夹
- 水晶报表怎样将一张表分两块显示出来
这种问题你调一下就知道了,贴一大堆代码上来看不晕么
{
new SqlParameter("@userId",resume.User.UserId),//FK
new SqlParameter("@name",resume.Name),
new SqlParameter("@sex",resume.Sex),
new SqlParameter("@identityNo",resume.IdentityNo),
new SqlParameter("@birthdy",resume.Birthday),
new SqlParameter("@stature",resume.Stature),
new SqlParameter("@degree",resume.Degree),
new SqlParameter("@school",resume.School),
new SqlParameter("@marriage",resume.Marriage),
new SqlParameter("@occupation",resume.Occupation),
new SqlParameter("@career",resume.Career),
new SqlParameter("@specialty",resume.Specialty),
new SqlParameter("@email",resume.Email),
new SqlParameter("@phone",resume.Phone),
new SqlParameter("@address",resume.Address)
};
时候出现异常,但我能力有限,还请高人给瞅瞅哪里不对了,这个是照着书本吵的,我实在找不出哪里的问题了!
int newId = DBhelper.GetScalar(sql, para);这个一般返回的是object吧但是没有CTE... 友情提示 : 断点 newId
object obj = 5;
int num = obj;
这样会CTE的
resume.User
这两个对象可能为空,检查一下就知道原因了。
//根据resumeId获取简历
public static Resume GetResumeByResumeId(int resumeId)
{
string sql = "SELECT * FROM Resume WHERE ResumeId=@ResumeId";
int userId;
try
{
SqlDataReader reader = DBhelper.GetReader(sql, new SqlParameter("@ResumeId", resumeId));
if (reader.Read())
{
Resume resume = new Resume();
resume.ResumeId = (int)reader["resumeId"];
resume.Name = (string)reader["name"];
resume.Sex = (string)reader["sex"];
resume.IdentityNo = (string)reader["identityNo"];
resume.Birthday = (DateTime)reader["birthday"];
resume.Stature = (string)reader["stature"];
resume.Degree = (string)reader["degree"];
resume.School = (string)reader["school"];
resume.Marriage = (string)reader["marriage"];
resume.Occupation = (string)reader["occupation"];
resume.Career = (string)reader["career"];
resume.Specialty = (string)reader["specialty"];
resume.Email = (string)reader["email"];
resume.Phone = (string)reader["phone"];
resume.Address = (string)reader["address"];
userId = (int)reader["userId"];//FK 楼主检查下这里是否为null
reader.Close();
resume.User = UserService.GetUserByUserId(userId);
return resume;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
方法中 new SqlParameter("@userId",company.User.UserId),//FK
这个地方显示,值为空!我在前台页面中数据源如何修改呢?这是前台插入代码的参数(就是利用gridview控件插入一个个人简历信息中,插入方法的参数):
<InsertParameters>
<asp:SessionParameter SessionField="userId" DefaultValue="userId" Name="userId" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="identityNo" Type="String" />
<asp:Parameter Name="birthday" Type="DateTime" />
<asp:Parameter Name="stature" Type="String" />
<asp:Parameter Name="degree" Type="String" />
<asp:Parameter Name="school" Type="String" />
<asp:Parameter Name="marriage" Type="String" />
<asp:Parameter Name="occupation" Type="String" />
<asp:Parameter Name="career" Type="String" />
<asp:Parameter Name="specialty" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="phone" Type="String" />
<asp:Parameter Name="address" Type="String" />
</InsertParameters>
现在调试后出现System.FormatException: 输入字符串的格式不正确。
书本上的代码是没有 <asp:SessionParameter SessionField="userId" DefaultValue="userId" Name="userId" Type="Int32" />的,但是没有的话,会报错说ObjectDataSource"odsResume"未能找到带参数的非泛型方法"AddResume": Name, Sex, IdentityNo, Birthday, Stature, Degree!
真不知道如何修改了,哪位能帮我看一下!谢谢了!或者加我Q568039554,我发送代码给您看一下!