VS2005中提示System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。怎么回事
protectedvoidPage_Load(objectsender,EventArgse){this.Title="显示书籍详细信息";//连接和打开数据库SqlCo...
protected void Page_Load(object sender, EventArgs e)
{
this.Title = "显示书籍详细信息";
//连接和打开数据库
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=localhost;database=book;integrated security=true";
conn.Open();
//执行SQL语句命令
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books where book_id=" + Request["bh"];
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "books");
DataList1.DataSource = ds.Tables["books"];
DataList1.DataBind();
conn.Close();
} 展开
{
this.Title = "显示书籍详细信息";
//连接和打开数据库
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=localhost;database=book;integrated security=true";
conn.Open();
//执行SQL语句命令
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books where book_id=" + Request["bh"];
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "books");
DataList1.DataSource = ds.Tables["books"];
DataList1.DataBind();
conn.Close();
} 展开
2个回答
展开全部
不知道你的数据库是结构怎么样!
如果 book_id 是 字符传形的
把下面的这句
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books where book_id=" + Request["bh"];
改为
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books where book_id='" + Request["bh"]+"'";
如果 book_id 是 字符传形的
把下面的这句
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books where book_id=" + Request["bh"];
改为
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books where book_id='" + Request["bh"]+"'";
追问
我的book_id是VARCHAR类型的,但是还有一个程序,代码和这个一样,就是字段和表名不一样,运行就能成功,怎么回事?
追答
那我的解答是正确的给分吧
2012-04-29
展开全部
是不是Request["bh"]为空啊?
改成这样
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books"+Request["bh"]?"":(" where book_id="+ Request["bh"].ToString().Trim());
改成这样
string sql = "select book_id,book_picture,book_name,book_price,book_note,ISBN_num,book_factory from books"+Request["bh"]?"":(" where book_id="+ Request["bh"].ToString().Trim());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询