Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scalar variable "@original_OrderID".

Status
Not open for further replies.

wallm

Programmer
Apr 4, 2005
69
GB
I've just installed the Northwind database in SQL Server Express 2005 and ran a script which clicked on a link to delete a record

This produced the following error

Must declare the scalar variable "@original_OrderID".

thanks.
 
need more info. what is your datasource, what object are you displaying the data in?
 
Here's the code, using SQL SERVER EXPRESS 2005 on my local machine.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "
<script runat="server">

</script>

<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>You Can Delete Order Detail Information for Orders that Have Included Shipments
of the Selected Product
</h2>
<asp:SqlDataSource ID="productListingDataSource" ConnectionString="<%$ ConnectionStrings:NWConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName] FROM [Products]" Runat="server">
</asp:SqlDataSource>
<asp:DropDownList ID="productSelector" Runat="server" DataSourceID="productListingDataSource"
DataTextField="ProductName" DataValueField="ProductID" AutoPostBack="True">
</asp:DropDownList>&nbsp;
<asp:SqlDataSource ID="orderDetailsForProduct" DataSourceMode="DataReader" ConnectionString="<%$ ConnectionStrings:NWConnectionString %>"
SelectCommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details] WHERE ([ProductID] = @ProductID2)"
Runat="server" DeleteCommand="DELETE FROM [Order Details] WHERE [OrderID] = @original_OrderID AND [ProductID] = @original_ProductID">
<DeleteParameters>
<asp:parameter Type="Int32" Name="OrderID"></asp:parameter>
<asp:parameter Type="Int32" Name="ProductID"></asp:parameter>
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter Name="ProductID2" Type="Int32" ControlID="productSelector"
PropertyName="SelectedValue"></asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>

<asp:GridView ID="orderDetailsGridView" Runat="server" AutoGenerateColumns="False" DataSourceID="orderDetailsForProduct" DataKeyNames="OrderID,ProductID" BorderColor="Tan" CellPadding="2" BackColor="LightGoldenrodYellow" BorderWidth="1px" ForeColor="Black" GridLines="None">
<FooterStyle BackColor="Tan"></FooterStyle>
<PagerStyle ForeColor="DarkSlateBlue" HorizontalAlign="Center" BackColor="PaleGoldenrod"></PagerStyle>
<HeaderStyle Font-Bold="True" BackColor="Tan"></HeaderStyle>
<AlternatingRowStyle BackColor="PaleGoldenrod"></AlternatingRowStyle>
<Columns>
<asp:CommandField DeleteText="Delete Order Line Item" ShowDeleteButton="True"></asp:CommandField>
<asp:BoundField HeaderText="Order ID" DataField="OrderID" SortExpression="OrderID">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Quantity" DataField="Quantity" SortExpression="Quantity" DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Unit Price" DataField="UnitPrice" SortExpression="UnitPrice" DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
</Columns>
<SelectedRowStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedRowStyle>
</asp:GridView>&nbsp;</div>
</form>
</body>
</html>
 
In the SQLDataSource, make sure the OldValuesParameterFormatString="original_{0}"

This will allow you to use the @original_<fieldname> syntax.

This behavior was by default in beta1 of .NET 2.0, I believe, but you have to explicity set the oldvalues format now.

Alternatively, if you changed the name of your variables to @original_OrderID and @original_ProductID to @OrderID and @ProductID, you'd probably also get it to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top