日期:2014-05-18  浏览次数:20518 次

不能查询到数据,请帮我修改一下
在接收参数的页面中直接使用Response.Write(Request.QueryString("name").ToString())输出数据正常,而在使用selectcommand查询时却没有任何反应,请帮我修改一下,代码如下:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="sp_in_detail.aspx.vb" Inherits="Sp_in_sp_in_detail" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>无标题页</title>
</head>
  <%
   
  Response.Write(Request.QueryString("name").ToString())  '这里输出正常
  Dim spname As String = Request.QueryString("name").ToString()
%>

<body>
  <form id="form1" runat="server">
  <div>
   
  <asp:SqlDataSource ID="SqlDataSource1" 
  connectionstring="server=(local);database=shangpinjinxiaocun;uid=sa;pwd="
  selectcommand="select * from sp_jin where name='&spname&'" '这里却没有任何反应,没查询到数据
  runat="server"></asp:SqlDataSource>
   
  <asp:GridView ID="GridView1" runat="server"
  datasourceid="SqlDataSource1">
  </asp:GridView>
  &nbsp;
  </div>
  </form>
</body>
</html>


------解决方案--------------------
selectcommand="select * from sp_jin where name='&spname&'"是用编译器器生成的吗?,如果是,那应该没有问题。还有这个&spname&变量可能有问题吧,建议直接用代码绑定,这样灵活些。
------解决方案--------------------
应该是&spname&没有取到值的吧
建议写代码绑定 这样写不怎么好吧!