Solved

Detailsview won't Update

Posted on 2008-06-23
7
466 Views
Last Modified: 2013-11-26
I have created many gridview/detailsview screens but I can't figure out the problem with this one.

The Detailsview shows the edit buttons, and allows the user to go thru the process of making a change.  But the database simply does not update after the edit link is clicked.  No errors are generated, just nothing changes in the database.

This has happened before, and I was able to fix it, by checking to make sure the Update statement was corrent -- But I can't seem to find the problem this time....

Any help would be greatly appreciated.
Datasource:
 
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:OnsiteServicesConnection %>" 
        DeleteCommand="DELETE FROM [Hardware] WHERE [ID] = ?" 
        ProviderName="<%$ ConnectionStrings:OnsiteServicesConnection.ProviderName %>" 
        SelectCommand="SELECT * FROM Hardware WHERE (ID = ?)" 
        
        UpdateCommand="UPDATE [Hardware] SET [MachineName] = ?, [MachineDesc] = ?, [Model] = ?, [MachineSerial]=?, [ServicePhone]=?, 
        [FirmwareVer]=?, [IPAddress]=?, [MACAddress] = ?, [DomainName] = ?, [Notes] = ? WHERE [ID] = ?">
        <SelectParameters>
            <asp:SessionParameter Name="ID" SessionField="SelectedID" Type="String" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="MachineName" Type="String" />
            <asp:Parameter Name="MachineDesc" Type="String" />
            <asp:Parameter Name="Model" Type="String" />
            <asp:Parameter Name="MachineSerial" Type="String" />
            <asp:Parameter Name="ServicePhone" Type="String" />
            <asp:Parameter Name="FirmwareVer" Type="String" />
            <asp:Parameter Name="IPAddress" Type="String" />
            <asp:Parameter Name="MACAddress" Type="String" />
            <asp:Parameter Name="DomainName" Type="String" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
 
 
 
Detailsview:
 
 
<asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" 
                                CellPadding="4" DataKeyNames="ID" 
                                DataSourceID="SqlDataSource2" Font-Names="Arial" Font-Size="Small" 
                                ForeColor="#333333" GridLines="None" Height="50px" Width="100%" 
                                HeaderText="Details">
                                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
                                <RowStyle BackColor="#EFF3FB" />
                                <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" Width="170px" />
                                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                <EmptyDataTemplate>
                                    No Data Found
                                </EmptyDataTemplate>
                                <Fields>
                                    <asp:BoundField DataField="MachineName" HeaderText="Device Name" 
                                        SortExpression="MachineName" />
                                    <asp:BoundField DataField="MachineDesc" HeaderText="Description" 
                                        SortExpression="MachineDesc" />
                                    <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
                                    <asp:BoundField DataField="MachineSerial" HeaderText="MachineSerial" 
                                        SortExpression="MachineSerial" />
                                    <asp:BoundField DataField="FirmwareVer" HeaderText="Firmware Version" 
                                        SortExpression="FirmwareVer" />
                                    <asp:BoundField DataField="IPAddress" HeaderText="IP Address" 
                                        SortExpression="IPAddress" />
                                    <asp:BoundField DataField="MACAddress" HeaderText="MAC Address" 
                                        SortExpression="MACAddress" />
                                    <asp:BoundField DataField="DomainName" HeaderText="Domain Name" 
                                        SortExpression="DomainName" />
                                    <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
                                    <asp:BoundField DataField="TimeAdded" DataFormatString="{0:d}" 
                                        HeaderText="Date Added" SortExpression="TimeAdded" ReadOnly="True" />
                                    <asp:TemplateField HeaderText="Attached Plotter" 
                                        SortExpression="ParentMachineSerial">
                                        <InsertItemTemplate>
                                            <asp:TextBox ID="TextBox1" runat="server" 
                                                Text='<%# Bind("ParentKey") %>'></asp:TextBox>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <asp:LinkButton ID="LinkButton2" Text='<%# Bind("ParentKey") %>' ToolTip='<%# Bind("ParentKey") %>'
                                                runat="server" onclick="LinkButton2_Click"></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Attached Scanner">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="LinkButton3" runat="server" 
                                                Text='<%# Session["ChildID"] %>'  ToolTip='<%# Session["ChildID"] %>' onclick="LinkButton3_Click"></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField ShowEditButton="True" />
                                </Fields>
                                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <EditRowStyle BackColor="#2461BF" />
                                <AlternatingRowStyle BackColor="White" />
                            </asp:DetailsView>

Open in new window

0
Comment
Question by:dparkes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 9

Expert Comment

by:Tone' Shelby
ID: 21852011
Is this a table you have been able to update before or is this the first attempt to do so? If first time I would check the update permissions on the table. This can occur if update permissions are not allowed on the table from the SQL  / db admin side.
0
 
LVL 1

Author Comment

by:dparkes
ID: 21852103
Other pages that affect the same table work perfectly.  I just checked.  There are a few minor differences in the way the pages are structured but I didn't think it would make any difference, like this select command doesn't match the update command on this page.  Select and Update don't need to match, do they?
0
 
LVL 9

Accepted Solution

by:
Tone' Shelby earned 500 total points
ID: 21852201
Yes It could if the select dat pulled back isn't the data being updated for sure say if the id is even slightly different and more specifically if the DataSource ID is the same if so. You may try checking this by say renaming one or the other of the datasource ID to make a quick check and then change it back if not.
Also I've not seen ? used so much like you have here as well...but if it has worked for you in the past..

Here is some sample code for instance: when using a Master Detail With GridView and DetailsView each Datasouce is different here .....&  no  question marks. I use this all inclusive  template as a starting point maybe it could help you?
{attached)

Hope it helps ...
0
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 9

Expert Comment

by:Tone' Shelby
ID: 21852209
Ooops forgot the attachment ..here ya go ! :)
Master-Detail-With-GridView-and-.txt
0
 
LVL 9

Expert Comment

by:Tone' Shelby
ID: 21852221
One more thing, notice the DataKeyNames in the attached it assures the record being updated is the one you choose on the screen too.
0
 
LVL 9

Expert Comment

by:Tone' Shelby
ID: 21852294
My sincerest apolgies I sent you just the details view without editing / update capabilities ...here is the file I mean to send you ...way too late to be answering questions on a Monday night I guess LOL { now attached}.
Guess you'll have two templates now if you need them ...

New file attached with  now editing capabilities ...

Also I highly recommend moving commands ecspecially at least your update commands to DB a stored procedure as it reduces the risk of injection attacks for sure. { the attached with included was for viewing  the SQL structure of course}

To be able to use this Update scenario with a Stored Procedure, only two lines need to be addressed. First, of course, change the UpdateCommand property to the actual name of the newly  Stored Procedure. Then, assign 'Stored Procedure" to the 'UpdateCommandType' property:

 UpdateCommand="procUpdateAuthors"
 UpdateCommandType="storedProcedure"

{and the same way for the other Select commands with other sps if you do)

Hope it helps ...

Master-Detail-Editing-with-Detai.txt
0
 
LVL 1

Author Comment

by:dparkes
ID: 21856656
tshel,

Thanks for you suggestions, particularly with regard to using stored procedures for added security.  I never thought of that, and will definitely look into it.

It turns out my main problem has to do with the way I'm storing the ID.  It's actually in a session variable (I know that's not obvious in the code), but the session variable is not correct when it needs to be.  I still need to fix this, but at least I know the problem now.  When the ID is hardcoded it works.  Thanks again.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question