Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

formview update and delete

Posted on 2006-10-24
10
Medium Priority
?
1,142 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
[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
  • 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
Industry Leaders: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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