0

我正在尝试创建一个 ASP.NET 网页来输出一个文本框,然后用户将在此文本框中输入密钥,然后我使用该密钥在 SQL 代码中放入 WHERE 条件以输出与该密钥匹配的数据。例如,用户在文本框中输入 ArtistID,我需要使用 SPEEDOFSALEREPORT 打印表格

SELECT * FROM SPEEDOFSALEREPORT WHERE ArtistID = "用户刚刚输入的密钥"

但我不知道怎么做。我下面的代码创建一个文本框并打印表中的所有行。请给我一个提示。我整天都在谷歌上搜索,但找不到答案。谢谢你。

这是我更新的 Default.aspx

    <body>
    <form id="form1" runat="server">
    <asp:TextBox ID="txtArtistID" runat="server" /><br /><br />
    <asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="submit" />

    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="TRANSACTIONID" HeaderText="TRANSACTIONID" 
                    SortExpression="TRANSACTIONID" />
                <asp:BoundField DataField="WORKID" HeaderText="WORKID" 
                    SortExpression="WORKID" />
                <asp:BoundField DataField="ARTISTID" HeaderText="ARTISTID" 
                    SortExpression="ARTISTID" />
                <asp:BoundField DataField="DATEACQUIRED" HeaderText="DATEACQUIRED" 
                    SortExpression="DATEACQUIRED" />
                <asp:BoundField DataField="DATESOLDID" HeaderText="DATESOLDID" 
                    SortExpression="DATESOLDID" />
                <asp:BoundField DataField="TURNAROUNDDAYS" HeaderText="TURNAROUNDDAYS" 
                    SortExpression="TURNAROUNDDAYS" />
                <asp:BoundField DataField="ASKINGPRICE" HeaderText="ASKINGPRICE" 
                    SortExpression="ASKINGPRICE" />
                <asp:BoundField DataField="SALESPRICE" HeaderText="SALESPRICE" 
                    SortExpression="SALESPRICE" />
                <asp:BoundField DataField="SALESMARGIN" HeaderText="SALESMARGIN" 
                    SortExpression="SALESMARGIN" />
            </Columns>
        </asp:GridView>
    </div>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="Data Source=oracle2;User ID=****;Password=****;Unicode=True" 
    ProviderName="System.Data.OracleClient" 
    SelectCommand="SELECT * FROM SPEEDOFSALEREPORT WHERE ARTISTID = @artistID;">

    <SelectParameters>
        <asp:ControlParameter Name="artistID" ControlID="txtArtistID" PropertyName="Text" />
    </SelectParameter>
</asp:SqlDataSource>

    </form>
</body>
4

3 回答 3

2

检查这一行:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="Data Source=oracle2;User ID=******;Password=***********;Unicode=True" 
        ProviderName="System.Data.OracleClient" 
        SelectCommand="SELECT * FROM SPEEDOFSALEREPORT">

正确使用这个:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="Data Source=oracle2;User ID=******;Password=***********;Unicode=True" 
        ProviderName="System.Data.OracleClient" 
        SelectCommand="SELECT * FROM SPEEDOFSALEREPORT"
        FilterExpression="Artistid='{0}'">

       <FilterParameters><asp:ControlParameter Name="" ControlID="ArtistID" PropertyName="Value"/>  
        </FilterParameters>  

于 2013-04-10T13:34:00.500 回答
1

您需要使用 ArtistID 作为参数,并更改您的文本框和提交按钮到 ASP 控件,如下所示:

<asp:TextBox ID="txtArtistID" runat="server" /><br /><br />
<asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="submit" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="Data Source=oracle2;User ID=******;Password=***********;Unicode=True" 
    ProviderName="System.Data.OracleClient" 
    SelectCommand="SELECT * FROM SPEEDOFSALEREPORT WHERE ARTISTID = @artistID;">
    <SelectParameters>
        <asp:ControlParameter Name="artistID" ControlID="txtArtistID" PropertyName="Text" />
    </SelectParameters>
</asp:SqlDataSource>

然后在您的代码后面(VB.NET)中单击按钮上的网格绑定:

Protected Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
    GridView1.DataBind()
End Sub

或(C#):

protected void btnSearch_Click(Object sender, EventArgs e)
{
    GridView1.DataBind();
}
于 2013-04-10T13:39:04.447 回答
0
protected void Button1_Click(object sender, EventArgs e){
        if (TextBox1.Text != ""){
        con.Open();
        int i = 0;
        SqlCommand cmd0 = new SqlCommand("select noticeid from TBLnotice where noticeid='" + TextBox1.Text + "'", con);
        i= int.Parse(cmd0.ExecuteScalar().ToString());
        if (i > 0){
            SqlCommand cmd1 = new SqlCommand("select notice from TBLnotice where noticeid='" + TextBox1.Text + "'", con);
            string name = cmd1.ExecuteScalar().ToString();
            txtadds.Text = name;
            TextBox1.Text = "";
            txtadds.Text = "";
            con.Close();
        }
        else{
            Label7.Visible = true;
            con.Close();
        }
    }
}
于 2015-02-17T10:25:26.483 回答