Must declare the scalar variable error.

atreyuxx

New member
Joined
Aug 21, 2006
Messages
1
Programming Experience
Beginner
Aha! You thought this was going to be an easy Must declare the scalar variable error message!


Well maybe it is, but not as easy as some of the ones I've seen out there. Basically, the problem area is the category dropdown that comes from a seperate table. This is almost verbatim from some of the tutorials that I have went to for reference on this issues. I get the following error when I try to update.

Must declare the scalar variable "@CategoryID".

<%@ Page Language="VB" %>
<html>
<
head id="Head1" runat="server">
<title>GridView Bound to SqlDataSource</title>
</
head>
<
body>
<form id="form1" runat="server">
<
asp:GridView id="EditGrid" DataSourceID="ProductSource" Runat="Server"
AutoGenerateColumns="False"
DataKeyNames="ID"
AutoGenerateEditButton="False"
AllowPaging="True"
PageSize="33"
PagerSettings-PageButtonCount="20"
PagerSettings-NextPageText=">"
CellPadding="3"
Width="100%"
HeaderStyle-Font-Size="10pt"
HeaderStyle-BackColor="#707070"
HeaderStyle-ForeColor="#FFFFFF"
RowStyle-Font-Size="10pt"
RowStyle-VerticalAlign="Top"
EditRowStyle-BackColor="Yellow">
<Columns>
<asp:TemplateField HeaderText="Edit" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Button ID="Button1" CommandName="Edit" Runat="Server" Text="Edit" Font-Size="8pt" Width="45px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btnUpdate" CommandName="Update" Runat="Server" Text="Update" Font-Size="8pt" Width="45px"/>
<asp:Button ID="btnCancel" CommandName="Cancel" Runat="Server" Text="Cancel" Font-Size="8pt" Width="45px"/>
<asp:Button ID="btnDelete" CommandName="Delete" Runat="Server" Text="Delete" Font-Size="8pt" Width="45px"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<asp:Label ID="Label1" Text='<%# Eval("Category") %>' Runat="Server"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="CategoryID" Runat="Server"
DataSourceID="CategorySource"
DataTextField="Category"
DataValueField="ID"
SelectedValue='<%# Bind("ID") %>'
Font-Size="9pt" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="SKU" DataField="SKU" SortExpression="SKU" ItemStyle-Width="75" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Title" DataField="Title" SortExpression="Title" ItemStyle-Width="300" />
<asp:BoundField HeaderText="UM" DataField="UM" ControlStyle-Width="30" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Price" DataField="Price" SortExpression="Price" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Panel ID="Panel1" Width="100%" Height="50px" Runat="Server" ScrollBars="Vertical">
<asp:Label ID="Label2" Text='<%# Eval("ShortDesc") %>' Runat="Server"/>
</asp:Panel>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="ShortDesc" Runat="Server"
Text='<%# Bind("ShortDesc") %>'
TextMode="MultiLine" Rows="5" Width="100%"
Font-Names="Arial" Font-Size="9pt"/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</
asp:GridView>
<asp:SqlDataSource ID="ProductSource" runat="server"
SelectCommand="SELECT a.*, b.Category FROM tblProducts a, tblProductCategories b WHERE a.CategoryID = b.ID ORDER BY SKU"
UpdateCommand="UPDATE tblProducts SET SKU = @sku, Title = @Title, UM = @UM, Price = @Price, ShortDesc = @ShortDesc, CategoryID = @CategoryID WHERE ID = @ID"
DeleteCommand="DELETE FROM tblProducts WHERE ID = @ID"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>">
</asp:SqlDataSource>
<asp:SqlDataSource ID="CategorySource" runat="server"
SelectCommand="SELECT * FROM tblProductCategories ORDER BY Category"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" />
</form>
</
body>
</
html>
 
Back
Top