Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | 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 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 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: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!

 


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
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



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


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