Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Beta Preview
This is the forum to discuss the Wrox book ASP.NET 2.0 Beta Preview by Bill Evjen; ISBN: 9780764572869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Beta Preview section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2004, 03:43 PM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Listing 4-9

I cannot get this listing to run correctly. I first tried typing it myself, then cut and pasted the downloaded listing and I get the same error.

When I click on Edit, change a column and then click on Update I get the error message...

"Must declare the variable '@CustomerID'"

Any ideas?
 
Old October 15th, 2004, 03:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Can you post your code?

Yippie Ki Yea, Mr. Falcon.
 
Old October 15th, 2004, 05:04 PM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I mentioned, I cut and pasted the code from the downloadable code on this website. Apart from correcting the quotes around the "VB" at the top of the page, it is exactly as downloaded from wrox.com.

Here it is...

<%@ Page Language="VB" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>SqlDataSource Control Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" Runat="server" Datasourceid="SqlDataSource1"
         AutoGenerateColumns="False" DataKeyNames="CustomerID"
         BackColor="White" GridLines="Vertical"
         BorderStyle="Solid" CellPadding="3" ForeColor="Black"
         BorderColor="#999999" BorderWidth="1px">
           <Columns>
              <asp:CommandField ShowEditButton="True">
              </asp:CommandField>
              <asp:BoundField SortExpression="CustomerID" HeaderText="CustomerID"
               ReadOnly="True" DataField="CustomerID">
              </asp:BoundField>
              <asp:BoundField SortExpression="CompanyName"
               HeaderText="Company Name" DataField="CompanyName">
              </asp:BoundField>
              <asp:BoundField SortExpression="Country" HeaderText="Country"
               DataField="Country">
              </asp:BoundField>
              <asp:BoundField SortExpression="Region" NullDisplayText="NO REGION"
               HeaderText="Region" DataField="Region">
              </asp:BoundField>
           </Columns>
           <FooterStyle BackColor="#CCCCCC">
           </FooterStyle>
           <SelectedRowStyle ForeColor="White" BackColor="#000099"
            Font-Bold="True">
           </SelectedRowStyle>
           <PagerStyle ForeColor="Black" HorizontalAlign="Center"
            BackColor="#999999">
           </PagerStyle>
           <HeaderStyle ForeColor="White" BackColor="Black" Font-Bold="True">
           </HeaderStyle>
           <AlternatingRowStyle BackColor="#CCCCCC">
           </AlternatingRowStyle>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" Runat="server"
         SelectCommand="Select * From Customers"
         UpdateCommand="UPDATE Customers SET CompanyName = @CompanyName, Country = @Country, Region = @Region WHERE (CustomerID = @CustomerID)"
         ConnectionString="Server=(local);Trusted_Connectio n=True;Integrated Security=SSPI;Persist Security Info=True;Database=Northwind"
         ProviderName="System.Data.SqlClient">
            <UpdateParameters>
                <asp:Parameter Name="CustomerID" Type="String">
                </asp:Parameter>
                <asp:Parameter Name="CompanyName" Type="String">
                </asp:parameter>
                <asp:parameter Name="Country" Type="String">
                </asp:parameter>
                <asp:parameter Name="Region" Type="String">
                </asp:parameter>
            </UpdateParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>
 
Old October 16th, 2004, 11:10 AM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just in case it wasn't obvious, I am referring to Listing 4-9 on page 88 of the book. It was mentioned in the subject of this topic, but I forgot to include it in the message itself.
 
Old October 21st, 2004, 09:12 AM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I assume someone else will hit this problem too, so here is the solution, directly from the author Bill Evjen. As is common with Beta products, Microsoft "tweaked" a few things!

Change the Update command to...

UpdateCommand="UPDATE Customers SET CompanyName = @CompanyName, Country = @Country, Region = @Region WHERE (CustomerID = @original_CustomerID)

...note the "original_" prefix on the CustomerID parameter.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing 8-10 and Listing 8-16. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 6th, 2008 01:11 PM
Problem listing database tables raphaelsenra Pro VB Databases 0 January 6th, 2005 11:38 AM
Security Listing Hal Levy SQL Server 2000 5 March 30th, 2004 04:43 PM
Listing records Adam H-W Classic ASP Basics 4 November 17th, 2003 12:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.