Solved

formview update and delete

Posted on 2006-10-24
10
1,139 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

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!

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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