当前位置:编程学习 > C#/ASP.NET >>

点击查看详细信息出错?


错误信息:
System.Data.SqlTypes.SqlNullValueException: 数据为空。不能对空值调用此方法或属性。 at System.Data.SqlTypes.SqlString.get_Value() at System.Data.SqlClient.SqlDataReader.GetString(Int32 i) at news.ShowNewsInfo.GetInfo() in d:\新闻系统\news\shownewsinfo.aspx.cs:line 60 

代码:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
GetValue();
if(id!=0)
{
GetInfo();
}
else
{
Response.Write("此新闻可能已经被删除!");
Response.End();
}
}
/// <summary>
/// 根据id取出新闻
/// </summary>
#region
private void GetInfo()
{
SqlConnection conn=null;
SqlCommand cmd=null;
SqlDataReader dr=null;
string sql=string.Empty;
try
{
sql=string.Format("select id,title,content,readtimes,classname,addtime,frominfo,titlecolor from newinfo where id={0}",this.id);
conn=news.Classes.DataBase.GetConn();
conn.Open();
cmd=new SqlCommand(sql,conn);
dr=cmd.ExecuteReader();
if(dr.Read())
{
this.title.Text="<span style='color:"+dr.GetString(7)+"'>"+dr.GetString(1)+"</span>";
sb.Append(dr.GetString(2));
this.info.Text="出自:"+dr.GetString(6)+"阅读次数:"+dr.GetInt32(3)+"发布时间:"+dr.GetDateTime(5);
}
}
catch(Exception ex)
{
Response.Write(ex);
}
finally
{
if(conn!=null)
conn.Close();
if(cmd!=null)
cmd.Dispose();
if(dr!=null)
dr.Close();
}
}
#endregion
/// <summary>
/// 取出其它页面传过来的id值
/// </summary>
#region
private void GetValue()
{
try
{
id=Convert.ToInt32(Request.QueryString["id"]);
}
catch
{
id=0;
}
}
#endregion --------------------编程问答-------------------- 路过帮顶 
============= 
11月6日,论坛升级公告,积分已经做了调整! 
http://topic.csdn.net/u/20081107/11/b27dc75f-14b1-4594-9de3-5b18d9e36a11.html 
此次调整增加了两个新的可用分获取渠道: 
1:帖子被推荐(加精)后,帖主可以获得88分的可用分奖励; 
2:帖子结帖后会返还帖主50%的悬赏分,无满意结帖不返还分数; 
3:接下来会不断增加新的可用分获取途径,比如参与活动赠送等,请大家多关注;
补充:.NET技术 ,  VC.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,