SqlDataReader Dr = Cmd.ExecuteReader();'=' 附近有语法错误。
using System;using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class Admin_View : System.Web.UI.Page
{
Db pn163 = new Db();
protected void Page_Load(object sender, EventArgs e)
{
//显示文章内容
SqlConnection Conn = new SqlConnection(pn163.strConn);
Conn.Open();
SqlCommand Cmd = new SqlCommand("select * from NewView where id ="
+Request.QueryString["id"], Conn);
SqlDataReader Dr = Cmd.ExecuteReader();
if (Dr.Read())
{
Titel.Text = Dr["Titel"].ToString();
Author.Text = "作者:" + Dr["Author"].ToString();
Time.Text = "添加时间:" + Dr["Time"].ToString().Substring(0,9);
Content.Text = Dr["Content"].ToString();
Hit.Text = "点击次数:" + Dr["Hit"].ToString();
}
Conn.Close();
}
}//提交网友评论
我这段代码不知道哪里出错了,这个是新闻浏览的页面,原来的文件有个添加留言的功能,我将相应的窗体和代码删除后只剩这个(中做删除,其它的没有改)。调试时提示SqlDataReader Dr = Cmd.ExecuteReader();'=' 附近有语法错误。但在IIS中照样能浏览,不知道是什么问题,哪位帮忙看看,小菜感激不尽! --------------------编程问答-------------------- 1,检查Request.QueryString["id"],的类型
2。SqlDataReader Dr 用完关掉 --------------------编程问答-------------------- 菜鸟一个,看不出什么错误,帮顶 --------------------编程问答-------------------- 我感觉很好的,是不是asp.net缓存的事,关了再开试试 --------------------编程问答-------------------- '=' 附近有语法错误
说的是SQL语句的错误
应为:
SqlCommand Cmd = new SqlCommand("select * from NewView where id ='"+Request.QueryString["id"]"'", Conn);--------------------编程问答-------------------- 上面少了个 + 号自己添上吧 --------------------编程问答-------------------- 真的对了啊
补充:.NET技术 , ASP.NET