Wrox Programmer Forums
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 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 Professional 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 August 27th, 2007, 04:03 PM
Authorized User
Join Date: May 2007
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default 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:

<%@ 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>
    <form id="form1" runat="server">
        <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" />
               <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" />
            <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: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" />


        <asp:Label ID="Label1" runat="server" Style="left: 102px; position: relative; top: 75px"

Old August 27th, 2007, 11:47 PM
Friend of Wrox
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts

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
Veris Consulting
Old August 28th, 2007, 07:24 AM
Authorized User
Join Date: May 2007
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts

thanks neil


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Gridview user007 ASP.NET 2.0 Basics 2 June 22nd, 2008 09:30 AM
VB Adding UpdateCommand Rich57 ASP.NET 2.0 Basics 0 May 30th, 2008 10:33 AM
the UpdateCommand affected 0 of the expected 1 rec theRealAirness ADO.NET 0 March 28th, 2005 04:23 PM
UpdateCommand ozzy VB.NET 2002/2003 Basics 4 January 24th, 2005 05:55 PM

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