1

I've spent way too long trying to figure out the answer to this question, so I thought it was time to ask. I'm trying to pass a value that the user input on the previous page into a sql query. I've tried every possible way I could find online to do this, but I just can't get it to work. In the _ space, I've tried

"'& myAge & '" " + myAge " & myAge @myAge $myAge

Pretty much every combination of quotes with @,&,and +, and I just cannot get it to work. I am not a web developer, but I'm working on an web app for my job and I could really use some help getting past this roadblock.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="gridview.aspx.vb" Inherits="TestWebsite.gridview" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
  <%
      Dim myAge
      myAge = Request.Form("inputAge")

%>

    Age: <%= myAge%>

    <form id="form1" runat="server">
    <div>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cs_test website %>" SelectCommand="SELECT * FROM [OARiskData$] WHERE AGE= _________"></asp:SqlDataSource>

        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
        </asp:GridView>

    </div>
    </form>
    <p>
        &nbsp;</p>
</body>
</html>
4

1 回答 1

2
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cs_test website %>" 
    SelectCommand="SELECT * FROM [OARiskData$] WHERE AGE= @Age">
    <SelectParameters>
        <asp:FormParameter DefaultValue="" Name="Age" FormField="inputAge" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>
于 2013-08-23T21:26:59.843 回答