各位,帮忙看看是什么错误啊????
cs中的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string newsid = Request.QueryString["newsID"].ToString(); SqlConnection con = DB.createCon();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "select * from newsTable where newsID='"+newsid+"'";
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
this.lbl_newsTitle.Text = sdr["newsTitle"].ToString();
this.Label1.Text = sdr["editer"].ToString();
this.Label2.Text = sdr["source"].ToString();
this.Label3.Text = sdr["upDatetime"].ToString();
this.lbl_content.Text = sdr["content"].ToString();
}
sdr.Close();
}
} GridView中:
<Columns>
<asp:TemplateField>
<ItemTemplate>
*
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="newsID" DataNavigateUrlFormatString="shownews.aspx?newsID={0}"
DataTextField="newsTitle" NavigateUrl="~/shownews.aspx" Target="_blank" />
</Columns> 错误提示:
无法找到资源。
说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
cs中的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string newsid = Request.QueryString["newsID"].ToString(); SqlConnection con = DB.createCon();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "select * from newsTable where newsID='"+newsid+"'";
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
this.lbl_newsTitle.Text = sdr["newsTitle"].ToString();
this.Label1.Text = sdr["editer"].ToString();
this.Label2.Text = sdr["source"].ToString();
this.Label3.Text = sdr["upDatetime"].ToString();
this.lbl_content.Text = sdr["content"].ToString();
}
sdr.Close();
}
} GridView中:
<Columns>
<asp:TemplateField>
<ItemTemplate>
*
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="newsID" DataNavigateUrlFormatString="shownews.aspx?newsID={0}"
DataTextField="newsTitle" NavigateUrl="~/shownews.aspx" Target="_blank" />
</Columns> 错误提示:
无法找到资源。
说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
错误:
未将对象引用设置到对象的实例。
?????
数据库里newsid为字符串?不是的话不要用'';
cmd.CommandText = "select * from newsTable where newsID="+newsid;
还有这个你确定是和你现在的页面在同一目录下吗,看一下是不是路径写错了
{
if (!this.IsPostBack)
{
string newsid = Request.QueryString["newsID"].ToString(); //十分大胆的写法:你确定一定会有newID传入么?如果你把地址栏传入的?newID=..去掉,会发生什么?string newsid =string.isNullOrEmpty(Request.QueryString["newsID"])?"0":Request.QueryString["newID"]; SqlConnection con = DB.createCon();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "select * from newsTable where newsID='"+newsid+"'"; //很明显的错误,如果newID是int类型
SqlDataReader sdr = cmd.ExecuteReader();
//建议在这里加个if(sdr!=null){
while (sdr.Read())
{
this.lbl_newsTitle.Text = sdr["newsTitle"].ToString();
this.Label1.Text = sdr["editer"].ToString();
this.Label2.Text = sdr["source"].ToString();
this.Label3.Text = sdr["upDatetime"].ToString();
this.lbl_content.Text = sdr["content"].ToString();
}
//}
sdr.Close();
}
}
应该是找不到这个页面吧?
应该是
NavigateUrl="~/shownews.aspx" 这里出了错吧
DataTextField="newsTitle" NavigateUrl="~/shownews.aspx" Target="_blank" />
string newsid = Request.QueryString["newsID"]==null?"".Request.QueryString["newsID"].ToString();