Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 May 8th, 2005, 06:00 AM
Authorized User
 
Join Date: May 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default GridView edit problem

I am following the data chapter in the beta book and I can't get my code to work :

<asp:GridView ID="GridView1" Width=500px
        DataSourceID="SqlDataSource1"
        CellPadding="3"
        Font-Names="arial"
        Font-Size="8pt"
        HeaderStyle-BackColor="#dcdcdc"
        HeaderStyle-Font-Bold="true"
        HeaderStyle-ForeColor="#00015E"
        FooterStyle-BackColor="#CCCCCC"
        SelectedRowStyle-BackColor="#FFFFFF"
        PagerStyle-BackColor=Gray
        PagerSettings-Mode=NumericFirstLast
        BackColor="#0066CC"
        Forecolor="white"
        PageSize="10"
        AllowPaging=true
        AllowSorting=true
        AutoGenerateColumns=false
        DataKeyNames="CompanyID"
        EditRowStyle-BackColor=Gold
        EditRowStyle-Font-Names="Arial"
        EditRowStyle-ForeColor=Black
        Runat="server">
            <Columns>
                <asp:BoundField Visible=false DataField="CompanyID" ReadOnly=true />
                <asp:BoundField HeaderText="Company Name" DataField="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField HeaderText="Location" DataField="CompanyLocation" SortExpression="CompanyLocation" />
                <asp:CheckBoxField HeaderText="Delivery" DataField="Delivery" SortExpression="Delivery" />
                <asp:BoundField HeaderText="Established" DataField="DateEstablished" SortExpression="DateEstablished" />
                <asp:BoundField HeaderImageUrl="~/Images/globe.jpg" DataField="Country" SortExpression="Country" NullDisplayText="N/A" />
                <asp:CommandField ShowEditButton=true ButtonType=Button />
                <asp:CommandField ShowDeleteButton=true ButtonType=Button />
            </Columns>
        </asp:GridView><BR />

        <asp:DetailsView ID="DetailsView1"
        DataSourceID="SqlDataSource1"
        AllowPaging=true
        Runat="server">
        </asp:DetailsView>

        <asp:SqlDataSource ID="SqlDataSource1" runat=server
        SelectCommand="SELECT * FROM COMPANY"
        ProviderName="<%$ ConnectionStrings:ourco.providerName %>"
        ConnectionString="<%$ ConnectionStrings:ourco%>"
        UpdateCommand="UPDATE Company SET CompanyName = @CompanyName, CompanyLocation = @CompanyLocation,
                        Delivery = @Delivery, DateEstablished = @DateEstablished, Country = @Country
                        WHERE CompanyID = @CompanyID"
        DeleteCommand="DELETE FROM Company WHERE CompanyID = @CompanyID">
            <UpdateParameters>
                <asp:Parameter Name="CompanyID" Type=Int32 />
                <asp:Parameter Name="CompanyName" Type=String />
                <asp:Parameter Name="CompanyLocation" Type=String />
                <asp:Parameter Name="Delivery" Type=Boolean />
                <asp:Parameter Name="DateEstablished" Type=DateTime />
                <asp:Parameter Name="Country" Type=String />
            </UpdateParameters>
            <DeleteParameters>
                <asp:Parameter Name="CompanyID" Type=Int32 />
            </DeleteParameters>
       </asp:SqlDataSource>

When I try to do an edit on a row I get the error :

Must declare the scalar variable "@CompanyID"

And when I try to delete a row, I don't get an error but nothing happens. Does anybody have any ideas what I am doing wrong?


Cheers,

Mike

 
Old May 9th, 2005, 01:32 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike,

Is it working when removing the column CompanyID (Any how you have set as the datakeyname of the gridview, you need'nt have a column and hide it)

Prashant

 
Old July 8th, 2005, 02:58 PM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mike...

I have encountered the same problem.
Any success in resolving it? - please let me know.

Thanks,

marek
 
Old July 13th, 2005, 01:26 PM
Wrox Author
 
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Bill Evjen
Default

There was a build somewhere between beta 1 to beta 2 where the where clause was changed to:

WHERE [CustomerID] = @original_CustomerID

They added the need for the @original_ part instead of just @CustomerID.

HTH, Bill Evjen

Bill Evjen
Wrox Author
Technical Director - Reuters
 
Old November 10th, 2005, 01:51 PM
Registered User
 
Join Date: Nov 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Found this out the hard way (after MUCH cursing and head-banging) .... and now that the release version of 2.o is out... you will have to remove the "original_" bit to make it work again .....



 
Old April 5th, 2006, 11:23 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So ...what is the solution here ?
I got the same problem with .net 2.0
Still could not figure out why update/delete does not work

Thanks

 
Old July 8th, 2006, 10:23 PM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, I've spend all day with a similar problem. Neither gridview or detailview would work for update or insert.

Ends up I had a field in the SQL database with a space in the name (Phone Number). It was converted to Phone_Number in generated code, or [Phone Number] at places.

I changed the field name to PhoneNumber and all is well now.

Hope this helps.

  Ed

 
Old July 9th, 2006, 05:17 AM
Registered User
 
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

maybee this is off topic. What do you mean by beta book? I have bought the asp.net 2.0 beginner but I dont understand what you mean with the beta book.


Lars

 
Old January 3rd, 2007, 07:59 PM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

add DataKeyNames="CompanyID" to your <asp:gridview> will solve your problem






Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Gridview to Edit NOT DetailsView ? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 December 4th, 2008 11:36 PM
Can not Edit gridview having TemplateField coolcoder2007 .NET Framework 2.0 4 March 6th, 2008 06:36 AM
edit item in gridview al-hijjawi Visual Studio 2005 0 December 27th, 2006 03:20 PM
edit gridview anurag_ur ASP.NET 2.0 Basics 3 June 21st, 2006 03:21 AM
edit gridview anurag_ur ASP.NET 2.0 Basics 0 June 20th, 2006 07:57 AM





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