这是我使用 SqlDataSource 和 GridView 的第一次体验,而且我是 ASP.Net 的新手,所以我正在努力让这些东西发挥作用。
我想从 SqlDataSource 创建一个 GridView,其中 SQL 查询中的变量来自表单文本框。我可以让查询和 GridView 在没有表单变量部分的情况下工作。这是我所拥有的:
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CUBE %>"
ProviderName="<%$ ConnectionStrings:CUBE.ProviderName %>"
SelectCommand="SELECT csono, citemno, nordqty, nseq, nprice, cdescript, nsalesamt FROM dbo.sostrs WHERE (LTRIM(csono) = @csono) ORDER BY nseq">
<selectparameters>
<asp:controlparameter name="csono" controlid="frmSONum" propertyname="Text"/>
</selectparameters>
</asp:SqlDataSource>
<asp:TextBox ID="frmSONum" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="citemno" HeaderText="citemno"
SortExpression="citemno" />
<asp:BoundField DataField="cdescript" HeaderText="cdescript"
SortExpression="cdescript" />
<asp:BoundField DataField="nordqty" HeaderText="nordqty"
SortExpression="nordqty" />
<asp:BoundField DataField="nprice" HeaderText="nprice"
SortExpression="nprice" />
<asp:BoundField DataField="nsalesamt" HeaderText="nsalesamt"
SortExpression="nsalesamt" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
</form>
当我按原样运行表单时,出现此错误:
ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@csono'.