Newbie having trouble getting GridView to work

hosnathalvir

New Member
This is my first experience with using SqlDataSource and GridView, and I'm new to ASP.Net, so I'm struggling to make some of this stuff work. I want to create a GridView from a SqlDataSource with a variable in the SQL Query coming from a form textbox. I can get the query and GridView to work without the form variable portion. Here is what I have:\[code\]<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>\[/code\]When I run the form as-is I get this error:\[code\]ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@csono'.\[/code\]
 
Back
Top