Solved

formview update and delete

Posted on 2006-10-24
10
1,135 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now