Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

formview update and delete

Posted on 2006-10-24
10
Medium Priority
?
1,145 Views
Last Modified: 2008-01-09
I have the following formview setup with the following objectdatasource. I am not sure why the Update or Delete is not working. Am I passing in the wrong type of parameter or something? I'm sorry for all the code, but i think it might be necessary. When I debug in the OnUpdated function I find the e.AffectedRows = -1. Any ideas? Thanks in advances:

<asp:FormView ID="InfoFormView" runat="server" DataSourceID="FormViewDataSource"
                    DataKeyNames="SchoolID" OnItemDeleted="InfoFormView_ItemDeleted" OnItemInserted="InfoFormView_ItemInserted"
                    OnItemUpdated="InfoFormView_ItemUpdated" DefaultMode="Insert" OnModeChanging="InfoFormView_ModeChanging" OnItemUpdating="InfoFormView_ItemUpdating">
                    <EditItemTemplate>
                        Name:
                        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' ></asp:TextBox><br />
                        County:
                        <asp:DropDownList ID="CountyListBox" runat="server" DataSourceID="CountyDataSource"
                            DataTextField="Name" SelectedValue='<%# Bind("CountyID") %>'
                            DataValueField="CountyID">
                        </asp:DropDownList><br />
                        <br />
                        <asp:Button ID="UpdateButton" runat="server" Text="Update" CommandName="Update" >
                        </asp:Button>
                        <asp:Button ID="DeleteButton" runat="server" Text="Delete" CommandName="Delete" >
                        </asp:Button>
                        <asp:Button ID="CancelButton" runat="server" Text="Cancel" CommandName="Cancel" >
                        </asp:Button>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        Name:
                        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' ></asp:TextBox><br />
                        County:
                        <asp:DropDownList ID="CountyListBox" runat="server" DataSourceID="CountyDataSource"
                            DataTextField="Name" SelectedValue='<%# Bind("CountyID") %>'
                            DataValueField="CountyID">
                        </asp:DropDownList><br />
                        <asp:Button ID="InsertButton" runat="server" Text="Submit" CommandName="Insert" >
                        </asp:Button>
                        <asp:Button ID="CancelButton" runat="server" Text="Cancel" CommandName="Cancel" >
                        </asp:Button>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        SchoolID:
                        <asp:Label ID="SchoolIDLabel" runat="server" Text='<%# Eval("SchoolID") %>' ></asp:Label><br />
                        Name:
                        <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>'></asp:Label><br />
                        CountyID:
                        <asp:Label ID="CountyIDLabel" runat="server" Text='<%# Bind("CountyID") %>'></asp:Label><br />
                        Active:
                        <asp:CheckBox ID="ActiveCheckBox" runat="server" Enabled="false"
                            Checked='<%# Bind("Active") %>'></asp:CheckBox><br />
                        County:
                        <asp:Label ID="CountyLabel" runat="server" Text='<%# Bind("County") %>'></asp:Label><br />
                        <asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" CausesValidation="False"></asp:LinkButton>&nbsp;
                        <asp:LinkButton ID="DeleteButton" runat="server" Text="Delete" CommandName="Delete" CausesValidation="False"></asp:LinkButton>&nbsp;
                        <asp:LinkButton ID="NewButton" runat="server" Text="New" CommandName="New" CausesValidation="False"></asp:LinkButton>
                    </ItemTemplate>
                </asp:FormView>

<asp:ObjectDataSource ID="FormViewDataSource" runat="server" DeleteMethod="usr_DeleteSchoolByID"
            InsertMethod="usr_InsertNewSchool" OldValuesParameterFormatString="original_{0}"
            SelectMethod="usr_GetSchoolByID" TypeName="ScienceFairDataTableAdapters.SchoolTableAdapter"
            UpdateMethod="usr_UpdateSchoolByID">
            <DeleteParameters>
                <asp:Parameter Type="Int32" Name="Original_SchoolID"></asp:Parameter>
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Type="Int32" Name="Original_SchoolID"></asp:Parameter>
                <asp:Parameter Type="String" Name="Name"></asp:Parameter>
                <asp:Parameter Type="Int32" Name="CountyID"></asp:Parameter>
            </UpdateParameters>
            <SelectParameters>
                <asp:ControlParameter PropertyName="Value" Type="Int32" Name="SchoolID" ControlID="IDHF">
                </asp:ControlParameter>
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Type="String" Name="Name"></asp:Parameter>
                <asp:Parameter Type="Int32" Name="CountyID"></asp:Parameter>
            </InsertParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="CountyDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetData" TypeName="ScienceFairDataTableAdapters.CountyTableAdapter">
        </asp:ObjectDataSource>
0
Comment
Question by:strickdd
  • 4
  • 4
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17797863
I don't see where you are setting the ControlParameter for those.

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx

Bob
0
 
LVL 28

Author Comment

by:strickdd
ID: 17797931
I have the control parameter set and it is passing the correct number. This is not an issue as far as I can tell.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17797953
I see the ControlParameter for the SelectParameters, but not for the UpdateParameters and DeleteParameters.

Bob
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Author Comment

by:strickdd
ID: 17797993
That's because the update automatically send the original_SchoolID to the stored procedure. That cannot be changed and is automatically maintained. Unless you can explain how to overwrite it i don't think that is the issue.

I have this script as my sp:

CREATE PROCEDURE [dbo].usr_UpdateSchoolByID
(
      @original_SchoolID int,
      @Name varchar(200),
      @CountyID int
)

AS

      UPDATE [School]
         SET [Name] = @Name
              ,[CountyID] = @CountyID
      WHERE
            SchoolID = @original_SchoolID

the proper values are in the FormViewUpdateEventArgs object "e". It is just not updating according to the sp.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17798044
The next question is does the bound source have any changes that require updates to the table?

Bob
0
 
LVL 28

Author Comment

by:strickdd
ID: 17798072
Yes, I have tried changing both fields on data that need to be updated. Again, they have the proper values in the FormViewUpdateEventArgs object, from what I can tell in debug.
0
 
LVL 28

Author Comment

by:strickdd
ID: 17805474
I figured out what the problem is. I was not selecting the ID column in my original SELECT statement.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17805505
Yep, that would do it.  I also checked to see if you can add ControlParameters to a InsertParameters/UpdateParameters/DeleteParameters, and that is true if you are overriding the default behavior of the ObjectDataSource, and not letting it determine the parameters from the SelectCommand.

Bob
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17929896
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

972 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