Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics 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 November 20th, 2012, 09:30 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default DetailView Update not working.

Hi all, new member stuck so need some help please

I'm following page 410 - Beginning ASP.NET 3.5


DB Name
  • dbo.A_TEST_SCOTT

Columns:
  • id (PK, int, not null)
  • name (varchar(50), null)
  • address (varchar(50), null)


I can insert OK into the database
I can't update, when i try to do this and check the results, nothing has changed :(

My DetailsView page is displaying the record ok based on the query string parameter so ?id=2 and ?id=3 pull through different records fine.


Here is my code, all drap and drop:

Code:
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert" 
        Height="50px" Width="125px">
        <Fields>
            <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
            <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
            <asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
            <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Commercial_db %>" 
        DeleteCommand="DELETE FROM [A_TEST_SCOTT] WHERE [id] = @id" 
        InsertCommand="INSERT INTO [A_TEST_SCOTT] ([id], [name], [address]) VALUES (@id, @name, @address)" 
        SelectCommand="SELECT [id], [name], [address] FROM [A_TEST_SCOTT] WHERE ([id] = @id)" 
        UpdateCommand="UPDATE [A_TEST_SCOTT] SET [name] = @name, [address] = @address WHERE [id] = @id">
        <SelectParameters>
            <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="address" Type="String" />
            <asp:Parameter Name="id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="address" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>

Code Behind

Code:
        
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString.Get("id") != null)
    {
       DetailsView1.DefaultMode = DetailsViewMode.Edit;
    }
}


any advise appreciated
  #2 (permalink)  
Old November 20th, 2012, 11:40 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok i think i may have figured out what wrong.

My code was in a Web User Control .ascx

When i tried again using a Web Form .aspx the update worked fine.

The problem is i'm using a CMS so can only use Web User Conrols... what can i do?
  #3 (permalink)  
Old November 20th, 2012, 02:45 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

This should work in User Controls as well. Are you sure you're passing the correct query string parameter ("id") from the lost page to the edit page that contains the UC?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #4 (permalink)  
Old November 21st, 2012, 07:35 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, thanks for taking the time to post back, and so quickly

I tried a little experiment

i have saved my DetailsView which does the displaying/editing/inserting in a control: dv.ascx

i have then created a webform.aspx and a webusercontrol.ascx - both of these files include the dv.ascx control

as before, inserting from both webform.aspx and webusercontrol.ascx works fine

when it comes to editing, only webform.aspx works, webusercontrol.ascx does nothing. This is strange given that they are both using the exact same code contained in dv.ascx

I take it there is probably some underlying conflict with the CMS i'm using.

Last edited by scott100; November 21st, 2012 at 07:44 AM..
  #5 (permalink)  
Old November 21st, 2012, 02:23 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Try debugging the site and set a breakpoint in the code that looks at the Query string:

if (Request.QueryString.Get("id") != null)

Then put a watch on Request.QueryString.Get("id"). Maybe that's null? Or maybe the code in Page_Load doesn't fire at all?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #6 (permalink)  
Old March 30th, 2013, 03:54 AM
adamsmtih321
Guest
 
Posts: n/a
Default

I try to update the detailview control. got this error messsage. ObjectDataSource 'odsDetail' could not find a non-generic method 'Update
  #7 (permalink)  
Old March 30th, 2013, 09:47 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

How is this related to the original post? If I were you, I'd start a new thread, and supply lots more information and the current code you're working with.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 


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
How to update the gridview through a detailview fh84 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 December 18th, 2008 08:14 PM
Update Query Not Working Odifius BOOK: Beginning Access VBA 0 September 20th, 2006 11:33 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
UPDATE query is not working Sujit Joshi Beginning PHP 1 July 6th, 2005 04:07 PM



All times are GMT -4. The time now is 01:53 PM.


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