Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 5th, 2006, 12:12 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Binding - Editing GridView Row Data

In my book at page 363 the authors start explaining how to set things up to enable data update - editing a row in other words.

We get the content for the SqlDataSource's UpdateCommand which contains "UPDATE [Customers] SET [CompanyName] = @CompanyName ... WHERE [CustomerID] = @original_CustomerID".

Then in the explanation they mention these "@something" explaining what they are:parameters or placeholders for the corresponding information from the selected row in the GridView. This is pretty good so far but this time, however they talk about a @CustomerID parameter, completely ignoring that a few lines above they wrote @original_CustomerID.

Of course the code is not working this way so I changed @original_CustomerID to @CustomerID which did nothing to fix my problem. I was not getting the error anymore but no update whatsoever.

I'm pretty pissed off with them ignoring to explain this and many other things.Not to mention that the book could've been half the number of pages - a lot of bla, bla, bla on not so important matters like what you can do without coding at all. There are hundreds of documents and webcasts on how to do that already. They should've made the book lighter and fill it with substance.

I found something: a SqlDataSource parameter called OldValuesParameterFormatString which has to do with this but I don't want to detail as I'm still doing research ... Of course, instead understanding it in 20 minutes, from the book I paid for, I have to waste a lot of time.

Thanks, Professional ASP 2.0 authors.

Oh, if anybody bothers to read these messages and has a clue about my problem, please, don't be shy. I just needed to express my disappointment.

  #2 (permalink)  
Old October 17th, 2006, 08:27 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shysusan
Default

I would be interested to know if you got a resolution to this as I am having the same problem (I am not a happy Susan with this book at the moment!):(

  #3 (permalink)  
Old January 11th, 2007, 10:34 AM
Authorized User
Points: 176, Level: 3
Points: 176, Level: 3 Points: 176, Level: 3 Points: 176, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the answer :))
The working example is here:http://aspspider.biz/chadfunk/SqlDat...ataUpdate.aspx

(Be aware)Due to the often server crashes, you may receive Errors.
If you get error, come back later.
(Server Crashes cause Connection string failure)
================================================== ===================
Page 363
Listing 11-22 to 11-27

//-------------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT * FROM [Customers]"
             UpdateCommand ="UPDATE [Customers] SET
                                     [CompanyName] = @CompanyName,
                                     [ContactName] = @ContactName,
                                     [ContactTitle] = @ContactTitle,
                                     [Address] = @Address,
                                     [City] = @City,
                                     [Region] = @Region,
                                     [PostalCode] = @PostalCode,
                                     [Country] = @Country,
                                     [Phone] = @Phone,
                                     [Fax] = @Fax
                                    WHERE [CustomerID] = @CustomerID
                            ">
                            
                             <UpdateParameters>
                                    <asp:Parameter Type ="string" Name ="CompanyName" Direction ="Input"/>
                                    <asp:Parameter Type ="string" Name ="ContactName" />
                                    <asp:Parameter Type ="string" Name ="ContactTitle" />
                                    <asp:Parameter Type ="string" Name ="Address" />
                                    <asp:Parameter Type ="string" Name ="City" />
                                    <asp:Parameter Type ="string" Name ="Region" />
                                    <asp:Parameter Type ="string" Name ="PostalCode" />
                                    <asp:Parameter Type ="string" Name ="Country" />
                                    <asp:Parameter Type ="string" Name ="Phone" />
                                    <asp:Parameter Type ="string" Name ="Fax" />
                                    <asp:Parameter Type ="string" Name ="CustomerID" />
                             </UpdateParameters>
            </asp:SqlDataSource>

------------

Gridview Code

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" Font-Names="Verdana" Font-Size="8.5pt">
            <Columns>
            <asp:CommandField ShowHeader ="True" HeaderText ="Command" ShowEditButton ="True" />
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly ="True" SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle" />
                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                <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:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
            </Columns>
        </asp:GridView>


/------------------------------------------------------------------
It works 100% :))
  #4 (permalink)  
Old December 30th, 2007, 09:47 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I bought your book in the spanish version and it looks great, but I have had problems with the Update command.
I have copied the code as it is and it still doesn't makes the update.

If you change the parameter "@CustomerID" for 'ALFKI', it always updates
the customer with customerID = 'ALFKI'.

If you remove the WHERE condition, it updates ALL the records.

It seems that the problem is that the program is not getting the parameter CustomerID for the "WHERE [CustomerID] = @CustomerID" in the UPDATE command.

Please assist!!! Thanx

BTW: It seems related to http://p2p.wrox.com/topic.asp?TOPIC_...pdate,gridview
  #5 (permalink)  
Old December 30th, 2007, 10:10 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Did you set the DataKeyNames as suggested in an earlier post?

Can you post the relevant parts of your code?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #6 (permalink)  
Old December 30th, 2007, 10:29 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've tested it with Northwind database and an example program and it works.

But when I try to adapt the code to my program it still doesn't work.

Thank you very much for your response...


The full code is here:

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

<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Gestión COLENF</title>
  <link rel="StyleSheet" type="text/css" media="screen" />
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <div>
        <asp:GridView ID="GV_Colegiados" runat="server" DataSourceID="SDS_Colegiados"
          DataKeyNames="COLEGIADO"
          AllowSorting="True" AllowPaging="True" PagerSettings-Position="Top"
          EmptyDataText="No se han encontrado coincidencias"
          AutoGenerateColumns="False">
          <Columns>
            <asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
            <asp:BoundField DataField="COLEGIADO" HeaderText="COLEGIADO" ReadOnly="True" SortExpression="COLEGIADO" />
            <asp:BoundField DataField="APELLIDOS" HeaderText="APELLIDOS" SortExpression="APELLIDOS" />
            <asp:BoundField DataField="NOMBRE" HeaderText="NOMBRE" SortExpression="NOMBRE" />
            <asp:CheckBoxField DataField="DEVOLUCION" HeaderText="DEVOLUCION" SortExpression="DEVOLUCION" />
            <asp:BoundField DataField="DIRECCION" HeaderText="DIRECCION" SortExpression="DIRECCION" />
            <asp:BoundField DataField="IUBICACION" HeaderText="IUBICACION" SortExpression="IUBICACION" />
            <asp:BoundField DataField="COMARCA" HeaderText="COMARCA" SortExpression="COMARCA" />
            <asp:BoundField DataField="POBLACION" HeaderText="POBLACION" SortExpression="POBLACION" />
            <asp:BoundField DataField="NCODPROV" HeaderText="NCODPROV" SortExpression="NCODPROV" />
            <asp:BoundField DataField="CODPOSTAL" HeaderText="CODPOSTAL" SortExpression="CODPOSTAL" />
            <asp:BoundField DataField="PAIS" HeaderText="PAIS" SortExpression="PAIS" />
            <asp:BoundField DataField="TELEFONO" HeaderText="TELEFONO" SortExpression="TELEFONO" />
            <asp:BoundField DataField="TELEFONO2" HeaderText="TELEFONO2" SortExpression="TELEFONO2" />
            <asp:BoundField DataField="CDNICIF" HeaderText="CDNICIF" SortExpression="CDNICIF" />
            <asp:BoundField DataField="TITULO 1" HeaderText="TITULO 1" SortExpression="TITULO 1" />
            <asp:BoundField DataField="TITULO 2" HeaderText="TITULO 2" SortExpression="TITULO 2" />
            <asp:BoundField DataField="FECHA DE NACIMIENTO" HeaderText="FECHA DE NACIMIENTO" SortExpression="FECHA DE NACIMIENTO" />
            <asp:BoundField DataField="SEXO" HeaderText="SEXO" SortExpression="SEXO" />
            <asp:BoundField DataField="E-MAIL" HeaderText="E-MAIL" SortExpression="E-MAIL" />
            <asp:CheckBoxField DataField="MOROSO" HeaderText="MOROSO" SortExpression="MOROSO" />
            <asp:BoundField DataField="SALDO" HeaderText="SALDO" SortExpression="SALDO" />
          </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SDS_Colegiados" runat="server" ConnectionString="<%$ ConnectionStrings:ACS_Colegiados %>"
          ProviderName="<%$ ConnectionStrings:ACS_Colegiados.ProviderName %>"
          SelectCommand="SELECT * FROM [Colegiados]"
          UpdateCommand="UPDATE [Colegiados] SET [Nombre]=@Nombre, [Apellidos]=@Apellidos, [CDNICIF]=@CDNICIF, [Direccion]=@Direccion WHERE [COLEGIADO]=@COLEGIADO ">
        </asp:SqlDataSource>
      </div>
    </div>
  </form>
</body>
</html>
:)

  #7 (permalink)  
Old December 30th, 2007, 10:51 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It finally works...

I had to put EXACTLY the same fields and in the same order inside the <columns> label and in the UPDATE command.

Saludos... :)

  #8 (permalink)  
Old December 30th, 2007, 11:07 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You may want to take a look here: http://msdn2.microsoft.com/en-us/library/ms228051(VS.80).aspx

If you need to customize the columns / fields, you need to create an <UpdateParameters> element....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Data from selected row in gridview JoinTTT ASP.NET 2.0 Professional 3 April 17th, 2007 02:14 AM
Data Binding from many Tables to Gridview khoder ASP.NET 2.0 Professional 1 February 19th, 2007 10:22 AM
Data Grid Editing in C# bmains C# 1 December 16th, 2004 04:23 AM
Binding to Filtered Data (or Data subsets) gdbjohnson C# 8 August 27th, 2004 01:59 PM
Manage data row by row in datagrid Dragonist Classic ASP Databases 5 July 29th, 2004 04:17 AM



All times are GMT -4. The time now is 03:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.