我菜鸟一个,正在学习阶段,做的模拟网站。出现问题了大家看看。
public string jibie;
protected void Page_Load(object sender, EventArgs e)
{
string name = Request.Cookies["username"].ToString();
string strSql = "select jibie from user_region where DengLuYongHuMing='"+name+"'";
jibie = Education.DBUtility.DbHelperSQL.GetSingle(strSql).ToString();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (jibie == "招生宝高级会员" || jibie == "终极会员")
{
Response.Redirect("zsbFB.aspx");
}
else
{
Response.Redirect("peixunkechengFB.aspx");
}
}
运行后出现的错误
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 18: string name = Request.Cookies["username"].ToString();
行 19: string strSql = "select jibie from user_region where DengLuYongHuMing='"+name+"'";
行 20: jibie = Education.DBUtility.DbHelperSQL.GetSingle(strSql).ToString();
行 21:
行 22: }
源文件: d:\My Documents\Visual Studio 2005\Projects\WebUI\huiyuan\Controls\Tree.ascx.cs 行: 20
public string jibie;
protected void Page_Load(object sender, EventArgs e)
{
string name = Request.Cookies["username"].ToString();
string strSql = "select jibie from user_region where DengLuYongHuMing='"+name+"'";
jibie = Education.DBUtility.DbHelperSQL.GetSingle(strSql).ToString();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (jibie == "招生宝高级会员" || jibie == "终极会员")
{
Response.Redirect("zsbFB.aspx");
}
else
{
Response.Redirect("peixunkechengFB.aspx");
}
}
运行后出现的错误
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 18: string name = Request.Cookies["username"].ToString();
行 19: string strSql = "select jibie from user_region where DengLuYongHuMing='"+name+"'";
行 20: jibie = Education.DBUtility.DbHelperSQL.GetSingle(strSql).ToString();
行 21:
行 22: }
源文件: d:\My Documents\Visual Studio 2005\Projects\WebUI\huiyuan\Controls\Tree.ascx.cs 行: 20
解决方案 »
- 修改webpartzone的标题
- 这句话怎么解释呢?("descendant::book[author/last-name='Austen']")
- 急~~~~DataTable修改问题,如何获取[行,列]中原来的值??
- csdn的高手们,你们能帮我解决c#的转码问题吗???????就是把一个string 从utf8转化成gb2312。。。
- 急!!!--存储过程的返回值,不对! 附代码
- 怎样给Excel文件添加网格线?
- |||||||||||| 求 助 ||||||||||||
- 输入一个地址,点击确定后出现该地址的经纬度的问题
- asp.net,如何实现类似QQ空间日志“上一篇、下一篇”的功能
- 推荐一个轮胎例子下载
- 新手:同一个sql语句,在sql server ems下可以执行,在c# 不能执行,为什么?
- Socket TCP 多客户端连接数据处理问题
GetSingle(strSql)
请单独检查这个的返回结果。
string strSql = "select jibie from user_region where DengLuYongHuMing='"+name+"'";
jibie = Education.DBUtility.DbHelperSQL.GetSingle(strSql).ToString();
将这里的代码更改成:
try{
string name = Request.Cookies["username"].ToString();
string strSql = "select jibie from user_region where DengLuYongHuMing='"+name+"'";
jibie = Education.DBUtility.DbHelperSQL.GetSingle(strSql).ToString();
}
catch(Exception exp)
{
System.Diagnostics.Debug.WriteLine(exp.Message);
}在输出窗口就可以看到错误信息了。
if (Request.Cookies["username"]!=null)
string name = Request.Cookies["username"].ToString();