Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old April 18th, 2008, 10:31 AM
Authorized User
 
Join Date: Aug 2007
Location: Colne, Lancashire, United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default DetailsView update not working.

Hi all,

I have a detailsview that I am trying to implement update functionality, but am having some issues:

Here's the code:

Code:
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:relOUPConnectionString %>"
            SelectCommand="SELECT * FROM [OUP_SAPData]" OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues" 

UpdateCommand="UPDATE [OUP_SAPData] SET [JobNo] = @JobNo, [GL_AccCode] = @GL_AccCode, 
[CostCentre] = @CostCentre, 
[SAPFirstCostOrderNo] = @SAPFirstCostOrderNo, 
[ISBN] = @ISBN, [SAPPONum] = @SAPPONum, 
[POConditionType] = @POConditionType 
WHERE [ID] = @original_ID AND 
[JobNo] = @original_JobNo AND 
[GL_AccCode] = @original_GL_AccCode AND
 [CostCentre] = @original_CostCentre AND
 [SAPFirstCostOrderNo] = @original_SAPFirstCostOrderNo AND
 [ISBN] = @original_ISBN AND 
[SAPPONum] = @original_SAPPONum AND 
[POConditionType] = @original_POConditionType">


            <DeleteParameters>
                <asp:Parameter Name="original_ID" Type="Int32" />
                <asp:Parameter Name="original_JobNo" Type="String" />
                <asp:Parameter Name="original_GL_AccCode" Type="String" />
                <asp:Parameter Name="original_CostCentre" Type="String" />
                <asp:Parameter Name="original_SAPFirstCostOrderNo" Type="String" />
                <asp:Parameter Name="original_ISBN" Type="String" />
                <asp:Parameter Name="original_SAPPONum" Type="String" />
                <asp:Parameter Name="original_POConditionType" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="JobNo" Type="String" />
                <asp:Parameter Name="GL_AccCode" Type="String" />
                <asp:Parameter Name="CostCentre" Type="String" />
                <asp:Parameter Name="SAPFirstCostOrderNo" Type="String" />
                <asp:Parameter Name="ISBN" Type="String" />
                <asp:Parameter Name="SAPPONum" Type="String" />
                <asp:Parameter Name="POConditionType" Type="String" />
                <asp:Parameter Name="original_ID" Type="Int32" />
                <asp:Parameter Name="original_JobNo" Type="String" />
                <asp:Parameter Name="original_GL_AccCode" Type="String" />
                <asp:Parameter Name="original_CostCentre" Type="String" />
                <asp:Parameter Name="original_SAPFirstCostOrderNo" Type="String" />
                <asp:Parameter Name="original_ISBN" Type="String" />
                <asp:Parameter Name="original_SAPPONum" Type="String" />
                <asp:Parameter Name="original_POConditionType" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="JobNo" Type="String" />
                <asp:Parameter Name="GL_AccCode" Type="String" />
                <asp:Parameter Name="CostCentre" Type="String" />
                <asp:Parameter Name="SAPFirstCostOrderNo" Type="String" />
                <asp:Parameter Name="ISBN" Type="String" />
                <asp:Parameter Name="SAPPONum" Type="String" />
                <asp:Parameter Name="POConditionType" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>


Now I can't see what i'm missing here. Any thoughts?
  #2 (permalink)  
Old April 18th, 2008, 10:37 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:Now I can't see what i'm missing here
The error message or problem description maybe? ;)

Can you please add line breaks in your code? This is near to impossible to read....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old April 18th, 2008, 10:58 AM
Authorized User
 
Join Date: Aug 2007
Location: Colne, Lancashire, United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get no errors, it returns to the page as expected, but doesn't update the details.

  #4 (permalink)  
Old April 19th, 2008, 07:26 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Andew,

Difficult to tell without the ability to try it out, or seeing other parts of your code.

Maybe the error is caused by the ConflictDetection? Maybe some fields are null, or get lost when the DetailsView posts back so the WHERE clause never finds the right record to update? To see if that's the problem, change the WHERE to:

WHERE [ID] = @original_ID

Also, make sure the DetailsView is set up correctly and uses the right keys and columns.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #5 (permalink)  
Old April 22nd, 2008, 10:17 AM
Authorized User
 
Join Date: Aug 2007
Location: Colne, Lancashire, United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Found the problem.

The reason it wasn't updating the entry was that in the DetailsView, I wasn't displaying the id (primary key) so the row in the table wasn't updating.

Do you know of any way to be able to update the row without having to display the id? It's not a major issue, I just would rather not have to show it...

Cheers for your help.

  #6 (permalink)  
Old April 22nd, 2008, 10:34 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you set the DataKeyNames property of the DetailsView to the primary key(s) of the record in the database?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #7 (permalink)  
Old April 22nd, 2008, 11:23 AM
Authorized User
 
Join Date: Aug 2007
Location: Colne, Lancashire, United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No I haven't....yet!

Will look that up and keep you posted, cheers!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Original Data via DetailsView Update kevorkian ASP.NET 2.0 Basics 5 May 29th, 2008 01:47 PM
Cannot Update the vals in a Dynamic DetailsView Itech ASP.NET 2.0 Professional 6 April 2nd, 2008 01:59 AM
DetailsView update onclick on LinkButton yukijocelyn ASP.NET 2.0 Basics 1 September 10th, 2007 03:43 AM
Update Code Not Working Odifius BOOK: Beginning Access VBA 0 September 19th, 2006 04:04 PM
Update not working... comicghozt ASP.NET 1.0 and 1.1 Basics 3 June 30th, 2006 03:28 AM





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