Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 1st, 2006, 01:47 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Binding Update Command

on page 364 there is, in the update command querystring, "@original_CustomerID"

where, what and how does "original_" fit in?

my real question is that i'm having problems updating ... in my where clause, i can't specify it to anything non-hard coded that isn't an editable text field when in edit mode. yet, i do not want the ID to be an editable field, even if i don't update it in the querystring ... what am i missing here?



here's my code:
****************************




<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:MoviesConnectionString %>"
        ProviderName="<%$ ConnectionStrings:MoviesConnectionString.ProviderN ame %>"
        SelectCommand="SELECT * FROM [All Movies]"
        UpdateCommand="UPDATE tblMovies SET [fldFind] = @fldFind where (fldID = @origional_fldID)"
        >
        <UpdateParameters>
            <asp:Parameter Type="String" Name="fldFind" />
        </UpdateParameters>

        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" AutoGenerateDeleteButton="True" DataKeyNames="fldID"
            DataSourceID="SqlDataSource1" EnableSortingAndPagingCallbacks="True" AutoGenerateEditButton="True" CellPadding="4" ForeColor="#333333" GridLines="None">
            <Columns>

                <asp:BoundField DataField="fldID" HeaderText="fldID" Visible=False InsertVisible="False"
                    SortExpression="fldID" />
                <asp:BoundField DataField="fldFind" HeaderText="fldFind" SortExpression="fldFind" />
                <asp:BoundField DataField="fldID" HeaderText="OK" />
                <asp:BoundField DataField="fldFind2" HeaderText="fldFind2" SortExpression="fldFind2" />
                <asp:BoundField DataField="fldFind3" HeaderText="fldFind3" SortExpression="fldFind3" />
                <asp:BoundField DataField="fldName" HeaderText="fldName" SortExpression="fldName" />
                <asp:BoundField DataField="fldType" HeaderText="fldType" SortExpression="fldType" />
                <asp:BoundField DataField="fldDescription" HeaderText="fldDescription" SortExpression="fldDescription" >
                    <HeaderStyle Width="500px" />
                </asp:BoundField>
                <asp:BoundField DataField="fldDate" HeaderText="fldDate" SortExpression="fldDate" />
                <asp:BoundField DataField="fldActors" HeaderText="fldActors" SortExpression="fldActors" />
                <asp:BoundField DataField="fldRating" HeaderText="fldRating" SortExpression="fldRating" />
                <asp:BoundField DataField="fldComments" HeaderText="fldComments" SortExpression="fldComments" />
                <asp:BoundField DataField="fldPersonalRating" HeaderText="fldPersonalRating" SortExpression="fldPersonalRating" />
                <asp:BoundField DataField="fldLanguage" HeaderText="fldLanguage" SortExpression="fldLanguage" />
                <asp:BoundField DataField="fldSubTitles" HeaderText="fldSubTitles" SortExpression="fldSubTitles" />
                <asp:BoundField DataField="fldPicture" HeaderText="fldPicture" SortExpression="fldPicture" />
                <asp:BoundField DataField="fldFormat" HeaderText="fldFormat" SortExpression="fldFormat" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <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>

Reply With Quote
  #2 (permalink)  
Old January 1st, 2006, 08:38 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I‚Äėm afraid that this code is based on Beta 2. You should set SqlDataSource.OldValuesParameterFormatString property to ‚Äúoriginal_{0}‚ÄĚ to solve this problem. It was the default value of that property in Beta 2. You can find more info here - http://www.asp.net/QuickStart/aspnet...x#updatedelete.
Reply With Quote
  #3 (permalink)  
Old January 2nd, 2006, 01:32 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm not sure i understand. i re-wrote the page 3 times and just cannot figure out how to update a row without saying "where fldID = 1".

"where fldID = @fldID" does not work.

i'm not writing any vb or C# code ... you're supposed to be able to do it without any code in asp.net 2.0

here's my new code ... it's very short. could someone fix it for me?:



************


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_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:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateEditButton="True" DataKeyNames="fldID" DataSourceID="AccessDataSource1" PageSize="2">
           <Columns>
               <asp:BoundField DataField="fldFind" HeaderText="fldFind" SortExpression="fldFind" />
               <asp:BoundField DataField="fldName" HeaderText="fldName" SortExpression="fldName" />
           </Columns>
        </asp:GridView>
        <br />
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="c:\inetpub\wwwroot\movies\movies.mdb"
            SelectCommand="SELECT * FROM [All Movies]"
            updatecommand="update tblMovies set fldName = @fldName where fldID = @fldID"
            >
            <UpdateParameters>
            <asp:Parameter Type="String" Name="fldName" />
            </UpdateParameters>
            </asp:AccessDataSource>
    </div>
    </form>
</body>
</html>





Reply With Quote
  #4 (permalink)  
Old January 2nd, 2006, 01:58 PM
Wrox Author
 
Join Date: Dec 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As Jan said the code changed between the beta and the final release. The Data Source will keep track of the original values for you so that you can use them to perform various logical operations between the old and new values if you need. In early releases, the Data Source object defaulted to using the prefix Original_{0} as t he Parameter prefix for those values, but in the final release this value was made configurable via the OldValueParameterFormatString attribute on the Data Source object.

The following code worked for me in the release version. All I did was add the OldValueParameterFormatString attribute to the Data Source, and then added the Parameter to the Update Parameters:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
     <title>Untitled Page</title>
</head>
<body>
     <form id="form1" runat="server">
     <div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            AllowSorting="True" AutoGenerateColumns="False" AutoGenerateEditButton="True"
            DataKeyNames="fldID" DataSourceID="AccessDataSource1" PageSize="2">
            <Columns>
                <asp:BoundField DataField="fldFind" HeaderText="fldFind" SortExpression="fldFind" />
                <asp:BoundField DataField="fldName" HeaderText="fldName" SortExpression="fldName" />
            </Columns>
         </asp:GridView>

         <br />

         <asp:AccessDataSource ID="AccessDataSource1" runat="server"
             DataSourceMode="DataSet"
             OldValuesParameterFormatString="original_{0}"
             DataFile="c:\inetpub\wwwroot\movies\movies.mdb"
             SelectCommand="SELECT * FROM [All Movies]"
             UpdateCommand="UPDATE [tblMovies] SET [fldName] = @fldName WHERE [fldID] = @fldID">
             <UpdateParameters>
                <asp:Parameter Type="String" Name="fldName" />
                <asp:Parameter Type="String" Name="original_fldID" />
             </UpdateParameters>
         </asp:AccessDataSource>
     </div>
     </form>
</body>
</html>



Reply With Quote
  #5 (permalink)  
Old January 2nd, 2006, 09:01 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, i see, this makes sense now.

the line: OldValuesParameterFormatString="original_{0}"

could you explain the "0" further? ... for example. what would 1 or 2 reference? ... if you edited and changed a row 3 times ... would all the changes be stored somewhere? if so, is it the hidden field? ... so many questions huh? ... ha ha.

is there a place where i could get a listing of all the properties and methods explained in detail for any object in the final .NET 2.0 framework?

i visited http://www.asp.net/QuickStart/ but i cannot find my answer there ... maybe i don't know how to find my answer because i don't know enough about what i'm doing. i did find the AccessDataSource under the Data Controls ... but the information is only a few lines ... very limited.

Reply With Quote
  #6 (permalink)  
Old January 3rd, 2006, 09:06 AM
Wrox Author
 
Join Date: Dec 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

{0} is just standard string formatter notation...basically like saying original_foo. Think of {0} as simply a placeholder in the string literal that can be replaced by a real value at runtime. I would guess that MSFT uses String.Format() (or somthing similar) to create the final string.

String.Format works like this:

Code:
String.Format("The quick {0}, fox {1} over the lazy {2}","brown","jumped","dog");
You can see that I have specified several different "variables" in the string, and then I just supply the values I want for those variables as the final three argument. The OldValueParameterFormatString is doing the same basic thing.

Make sense?

As far as documentation, the best place i can point you is the MSDN help. You can either use the built in VS help, or I sometimes use Google. Simply type in the object name you want info about, then add "site:msdn2.microsoft.com" to your query to tell Google to restrict its search results to the MSDN documentation website.

Devin

Reply With Quote
  #7 (permalink)  
Old January 4th, 2006, 11:59 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

pefect, i have a whole new confidence with this .NET stuff, thanks.

Reply With Quote
  #8 (permalink)  
Old December 30th, 2007, 09:52 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had a similar problem and I resolved it listing EXACTLY the same field inside the <columns> label and in the UPDATE sentence.

I hope it helps...

Reply With Quote
Reply


Thread Tools
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
Update command yogeshyl Oracle 0 November 28th, 2007 07:05 AM
Invalid UPDATE command Mr. Vage SQL Language 4 April 14th, 2007 05:59 PM
Binding a comboBox to update a listView Amethyst1984 VB How-To 2 February 28th, 2006 02:07 PM
Binding a combo box to update a list view Amethyst1984 General .NET 0 February 28th, 2006 02:04 PM
Update Command In DataGrid RPG SEARCH ASP.NET 1.0 and 1.1 Basics 9 February 21st, 2005 08:20 AM



All times are GMT -4. The time now is 10:12 PM.


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