p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   GridView UpdateCommand (http://p2p.wrox.com/showthread.php?t=61530)

Sheraz Khan August 27th, 2007 04:03 PM

GridView UpdateCommand
 
i am trying to update some records using the gridview. i have created my own updatecommand but the problem is that when i run this command in query builder it runsfine and update the desired recored but when i try to use it from the grid view, it doesnt update the record:

Code:


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="GridViewRetriefValues._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Style="left: 46px; position: relative; top: 22px"
            Text="Show Records" />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
            DataKeyNames="CustomerID" DataMember="DefaultView" DataSourceID="SqlDataSource1"
            ForeColor="#333333" GridLines="None" Style="left: 140px; position: relative;
            top: 33px" Visible="False" AllowSorting="True">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <Columns>
               <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:CommandField ShowEditButton="True" />
            </Columns>
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <EditRowStyle BackColor="#999999" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
        &nbsp;
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [CustomerID], [CompanyName], [City], [PostalCode], [Country], [Phone] FROM [Customers] where country='uk' "
            Updatecommand="UPDATE Customers SET CompanyName = @CompanyName, City = @City, PostalCode = @PostalCode, Country = @Country, Phone = @Phone WHERE (CustomerID = @orignal_CustomerID)">
        <UpdateParameters >
            <asp:Parameter Name= "Companyname" Type =String />
            <asp:Parameter Name ="City" Type =String />
            <asp:Parameter Name="PostalCode" />
            <asp:Parameter Name ="Country" Type =String />
            <asp:Parameter Name ="Phone" Type=String  />
            <asp:Parameter Name="orignal_Customerid" />

        </UpdateParameters>

        </asp:SqlDataSource>
        <asp:Label ID="Label1" runat="server" Style="left: 102px; position: relative; top: 75px"
            Text="Label"></asp:Label>&nbsp;
    </div>
    </form>
</body>
</html>



Cheers
Sheraz

thenoseknows August 27th, 2007 11:47 PM

Your parameter is named original_customerId but thats not wired up to anything in the gridview. Change your parameter to "customerId" and it should work.

Neil Timmerman
Programmer
Veris Consulting

Sheraz Khan August 28th, 2007 07:24 AM

thanks neil


Cheers
Sheraz


All times are GMT -4. The time now is 05:26 AM.

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