Solved

formview update and delete

Posted on 2006-10-24
10
1,136 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

10 Experts available now in Live!

Get 1:1 Help Now