Link to home
Start Free TrialLog in
Avatar of rnzimiro
rnzimiro

asked on

Updating from a Formview Control with an ObjectDataSource Control

Hi Experts,
I am trying to update a database from a Formview control in ASP>NET using an ObjectDataSource control as my business Object. The select method works fine but when I attempt to perform an update operation, I get the following error message.
<===================================================================================
ObjectDataSource 'MovieDetails' could not find a non-generic method 'UpdateMovies' that has parameters: movieName, ReleaseDate, synopsis, rating, language, filmColor, ratingID, locationCity, locationCountry, categoryID, filmCompany, movieID, editorReview, original_movieID
===================================================================================>
Here is the code
<==================================================================================
<%@ Page Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="moviedetails.aspx.cs" Inherits="admin_moviedetails" Title="Movie Details" ValidateRequest="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Label runat="server" ForeColor="red" ID="lblMessage" Text="" />
    <div>
        <asp:FormView ID="frmMovie" runat="server" DataKeyNames="movieID" DataSourceID="MovieDetails" BackColor="LightGoldenrodYellow"
        BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" Width="100%" OnDataBound="SetDefaults" OnItemUpdated="UpdateMovie">
        <HeaderTemplate>
            <asp:Label runat="server" ID="movieN" Text='<%# Bind("MovieName") %>'></asp:Label>
        </HeaderTemplate>
            <EditItemTemplate>
                <asp:HiddenField runat="server" ID="movieID" Value='<%# Bind("movieID") %>' />
                <div>
                    <table border="0" cellpadding="1" cellspacing="1" width="80%">  
                        <tr>
                            <td valign="top" width="15%" rowspan="5">
                                <asp:Image ID="moviePhoto" runat="server" Height="150" Width="150" />
                                <!--
                                <a href="javascript: ShowMoviePicDialog('<%# Eval("movieID") %> ','<%# Eval("moviePhotoName") %>')">Edit Picture</a>
                                -->
                            </td>
                            <td width="15%">Movie Name </td>
                            <td><asp:TextBox ID="movieName" runat="server" Text='<%# Bind("movieName") %>' ></asp:TextBox></td>
                            <td width="15%">Release Date </td>
                            <td><asp:TextBox ID="releaseDate" runat="server" Text='<%# Eval("ReleaseDate","{0:d}") %>' ></asp:TextBox></td>
                                          <td width="38%" rowspan="5" valign="top">
                                <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Animated="true" TargetControlID="releaseDate">
                                </ajaxToolkit:CalendarExtender>
                                          </td>
                                          <td rowspan="5">
                                              <div style="height:150px; overflow-y:auto; padding:0px">
                                              
                                              </div>
                                          </td>
                        </tr>
                        <tr>
                          <td>City filmed </td>
                          <td width="36%"><asp:TextBox ID="locationCity" runat="server" Text='<%# Bind("locationCity") %>'/></td>
                          <td width="10%">Country filmed </td>
                          <td width="38%">
                          <asp:DropDownList runat="server" ID="locationCountry" DataSourceID="sqlCountries" DataTextField="Country" DataValueField="Country"
                           SelectedValue='<%# Eval("locationCountry") %>'></asp:DropDownList>
                          <asp:SqlDataSource runat="server" ID="sqlCountries" ConnectionString='<%$ ConnectionStrings:MediafricanConnectionString %>' EnableCaching="true"
                           SelectCommand="SELECT * FROM Countries" />
                          </td>
                                    </tr>
                        <tr>
                          <td>MPARating</td>
                            <td> <asp:DropDownList ID="ratingID" runat="server" DataSourceID="mRating" DataTextField="ratingType" DataValueField="ratingID" SelectedValue='<%# Bind("ratingID") %>' />
                                 <asp:ObjectDataSource ID="mRating" runat="server" SelectMethod="GetAllMPARatings" TypeName="MeridianMoviesTableAdapters.MPARatingsTableAdapter" OldValuesParameterFormatString="original_{0}" /></td>
                            <td>Category </td>
                            <td><asp:DropDownList ID="categoryID" runat="server" DataSourceID="cat" DataTextField="categoryName" DataValueField="categoryID" SelectedValue='<%# Bind("categoryID") %>' />
                                <asp:ObjectDataSource ID="cat" runat="server" SelectMethod="GetAllCategories" TypeName="MeridianMoviesTableAdapters.CategoriesTableAdapter" OldValuesParameterFormatString="original_{0}" /></td>
                                    </tr>
                        <tr>
                          <td>Film Company </td>
                            <td><asp:TextBox ID="filmCompany" runat="server" Text='<%# Bind("filmCompany") %>' />  </td>
                            <td>Film Color </td>
                            <td><asp:TextBox ID="filmColor" runat="server" Text='<%# Bind("filmColor") %>'/> </td>
                                    </tr>
                        <tr>
                          <td>Language </td>
                            <td><asp:TextBox ID="language" runat="server" Text='<%# Bind("language") %>' /> </td>
                            <td>Film Rating </td>
                            <td><asp:TextBox ID="rating" runat="server" Text='<%# Bind("rating") %>' /> </td>
                                    </tr>
                    </table>
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Synopsis
                    </div>
                    <div>
                    <asp:TextBox ID="synopsis" runat="server" Text='<%# Bind("synopsis") %>' TextMode="MultiLine" Wrap="true" Width="100%" Rows="5" />
                    </div>
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Editors Review
                    </div>
                    <div>
                    <asp:TextBox ID="editorReview" runat="server" Text='<%# Bind("editorReview") %>' TextMode="MultiLine" Wrap="true" Width="100%" Rows="5" />
                    </div>
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Movie Cast
                    </div>
                    <div>
                    <a href="javascript: ShowDialog('dvActors')" style="font: 90% bold; text-decoration:none">[Add Cast to movie]</a>
                    </div>
                    <div>
                    <asp:UpdatePanel runat="server" ID="updActors" ChildrenAsTriggers="true">
                        <ContentTemplate>
                        <asp:Panel runat="server" ID="panel1" Direction="LeftToRight" HorizontalAlign="Justify" Wrap="true" Width="100%">
                            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="movieActors">
                                <ItemTemplate>
                                    <asp:LinkButton runat="server" ID="lnkRemoveActor" ToolTip="Click on the actor to remove them from the movie" CommandArgument='<%# Bind("actorid") %>'
                                     OnCommand="RemoveActor">
                                     <%# Eval("ActorName") %>(<%# Eval("stageName") %>)
                                     </asp:LinkButton>
                                     &nbsp;
                                </ItemTemplate>
                           </asp:Repeater>
                            <asp:ObjectDataSource runat="server" ID="movieActors" SelectMethod="GetMovieActors" TypeName="MeridianMoviesTableAdapters.MovieActorsTableAdapter">
                                <SelectParameters>
                                    <asp:ControlParameter Name="movieID" ControlID="movieID" PropertyName="value" DefaultValue="0" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                        </asp:Panel>
                        </ContentTemplate>
                     </asp:UpdatePanel>  
                    </div>
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Directors
                    </div>
                    <div>
                        <asp:Panel runat="server" ID="panel2" Direction="LeftToRight" HorizontalAlign="Justify" Wrap="true" Width="100%">
                                <asp:Repeater ID="Repeater2" runat="server" DataSourceID="movieDirectors">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="moviedirector" Text='<%# Bind("DirectorName") %>'></asp:Label> &nbsp;
                                    </ItemTemplate>
                               </asp:Repeater>
                                <asp:ObjectDataSource runat="server" ID="movieDirectors" SelectMethod="GetMovieDirectors" TypeName="MeridianMoviesTableAdapters.MovieDirectorsTableAdapter">
                                    <SelectParameters>
                                        <asp:ControlParameter Name="movieID" ControlID="movieID" PropertyName="value" DefaultValue="0" />
                                    </SelectParameters>
                                </asp:ObjectDataSource>
                        </asp:Panel>
                    </div>
                </div>
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="Save Changes">
                </asp:LinkButton>
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel Changes">
                </asp:LinkButton>
            </EditItemTemplate>
           
            <ItemTemplate>
                <asp:HiddenField runat="server" ID="movieID" Value='<%# Bind("movieID") %>' />
                <div>
                    <table border="0" cellpadding="1" cellspacing="1" width="70%">  
                        <tr>
                            <td valign="top" width="15%" rowspan="5">
                             <asp:Image ID="moviePhoto" runat="server" Height="150" Width="150" /><br />
                             <a href='addmoviephoto.aspx?mid=<%# Eval("movieID") %>&curPic=<%# Eval("moviePhotoName") %>' style="font-size:85%">[add/edit movie photo]</a>
                            </td>
                            <td width="15%">Movie Name </td>
                            <td><asp:Label ID="movie" runat="server" Text='<%# Bind("movieName") %>' ></asp:Label></td>
                            <td width="15%">Release Date </td>
                            <td><asp:Label ID="TextBox1" runat="server" Text='<%# Eval("ReleaseDate","{0:d}") %>' ></asp:Label></td>
                                          <td width="38%" rowspan="5">
                                               <div style="height:150px; overflow-y:auto; padding:0px">
                                              
                                              </div>
                                          </td>
                        </tr>
                        <tr>
                          <td>City filmed </td>
                          <td width="36%"><asp:Label ID="locationCity" runat="server" Text='<%# Bind("locationCity") %>'/></td>
                          <td width="10%">Country filmed </td>
                          <td width="38%"><asp:Label ID="locationCountry" runat="server" Text='<%# Bind("locationCountry") %>'/></td>
                                    </tr>
                        <tr>
                          <td>MPARating</td>
                            <td><asp:Label ID="lblRating" runat="server" Text='<%# Bind("MPARating") %>'/></td>
                            <td>Category </td>
                            <td><asp:Label ID="Label3" runat="server" Text='<%# Bind("category") %>' /></td>
                                    </tr>
                        <tr>
                          <td>Film Company </td>
                            <td><asp:Label ID="filmCompany" runat="server" Text='<%# Bind("filmCompany") %>' />  </td>
                            <td>Film Color </td>
                            <td><asp:Label ID="filmColor" runat="server" Text='<%# Bind("filmColor") %>'/> </td>
                                    </tr>
                        <tr>
                          <td>Language </td>
                            <td><asp:Label ID="Label2" runat="server" Text='<%# Bind("language") %>' /> </td>
                            <td>Film Rating </td>
                            <td><asp:Label ID="rating" runat="server" Text='<%# Bind("rating") %>' /> </td>
                                    </tr>
                                    <tr>
                                        <td colspan="5" align="right">
                                            [<asp:LinkButton Font-Bold="true" Font-Size="Small" runat="server" ID="lnkUpdate" CommandName="Edit" Text="Edit" />]
                                        </td>
                                    </tr>
                    </table>
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Synopsis
                    </div>
                    <div>
                    <asp:Literal ID="Synopsis" runat="server" Text='<%# Bind("synopsis") %>' Mode="Passthrough"></asp:Literal>
                    </div>
                    <div style="text-align:right">
                    [<asp:LinkButton Font-Bold="true" Font-Size="Small" runat="server" ID="LinkButton1" CommandName="Edit" Text="Edit" />]
                    </div>
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Editors Review
                    </div>
                    <div>
                    <asp:Literal ID="editorReview" runat="server" Text='<%# Bind("editorReview") %>' Mode="Passthrough"></asp:Literal>
                    </div>
                    <div style="text-align:right">
                    [<asp:LinkButton Font-Bold="true" Font-Size="Small" runat="server" ID="LinkButton2" CommandName="Edit" Text="Edit" />]
                    </div>
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Movie Cast
                    </div>
                    <div>
                        <asp:Panel runat="server" ID="panel1" Direction="LeftToRight" HorizontalAlign="Justify" Wrap="true" Width="100%">
                            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="movieActors">
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="movieActor" Text='<%# Bind("ActorName") %>'></asp:Label> &nbsp;
                                </ItemTemplate>
                           </asp:Repeater>
                            <asp:ObjectDataSource runat="server" ID="movieActors" SelectMethod="GetMovieActors" TypeName="MeridianMoviesTableAdapters.MovieActorsTableAdapter">
                                <SelectParameters>
                                    <asp:ControlParameter Name="movieID" ControlID="movieID" PropertyName="value" DefaultValue="0" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                        </asp:Panel>
                    </div>
                </div>
                <div style="text-align:right">
                    [<asp:LinkButton Font-Bold="true" Font-Size="Small" runat="server" ID="LinkButton3" CommandName="Edit" Text="Edit" />]
                </div>
                <div>
                    <div style="background-color:#D2B48C">
                    Directors
                    </div>
                    <div>
                        <asp:Panel runat="server" ID="panel2" Direction="LeftToRight" HorizontalAlign="Justify" Wrap="true" Width="100%">
                                <asp:Repeater ID="Repeater2" runat="server" DataSourceID="movieDirectors">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="moviedirector" Text='<%# Bind("DirectorName") %>'></asp:Label> &nbsp;
                                    </ItemTemplate>
                               </asp:Repeater>
                                <asp:ObjectDataSource runat="server" ID="movieDirectors" SelectMethod="GetMovieDirectors" TypeName="MeridianMoviesTableAdapters.MovieDirectorsTableAdapter">
                                    <SelectParameters>
                                        <asp:ControlParameter Name="movieID" ControlID="movieID" PropertyName="value" DefaultValue="0" />
                                    </SelectParameters>
                                </asp:ObjectDataSource>
                        </asp:Panel>
                    </div>
                    <div style="text-align:right">
                    [<asp:LinkButton Font-Bold="true" Font-Size="Small" runat="server" ID="LinkButton4" CommandName="Edit" Text="Edit" />]
                    </div>
                </div>
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                    Text="Edit">
                </asp:LinkButton>
                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                    Text="Delete">
                </asp:LinkButton>
            </ItemTemplate>
            <FooterStyle BackColor="Tan" />
            <EditRowStyle BackColor="White" ForeColor="Black" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" BorderStyle="Outset" Font-Italic="True" Font-Size="Medium" />
        </asp:FormView>
        &nbsp;
        <asp:ObjectDataSource ID="MovieDetails" runat="server" SelectMethod="GetMovieByID"
            TypeName="MeridianMoviesTableAdapters.MoviesTableAdapter" UpdateMethod="UpdateMovies" OldValuesParameterFormatString="original_{0}">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="-1" Name="movieID" QueryStringField="mid"
                    Type="Object" />
            </SelectParameters>
             <UpdateParameters>
                <asp:Parameter Name="MovieName" Type="String" />
                <asp:Parameter Name="ReleaseDate" Type="DateTime" />
                <asp:Parameter Name="synopsis" Type="String" />
                <asp:Parameter Name="rating" Type="Int32" />
                <asp:Parameter Name="language" Type="String" />
                <asp:Parameter Name="filmColor" Type="String" />
                <asp:Parameter Name="ratingID" Type="Int32" />
                <asp:Parameter Name="locationCity" Type="String" />
                <asp:Parameter Name="locationCountry" Type="String" />
                <asp:Parameter Name="categoryID" Type="Int32" />
                <asp:Parameter Name="filmCompany" Type="String" />
                <asp:Parameter Name="movieID" Type="Object" />
            </UpdateParameters>
        </asp:ObjectDataSource>
    </div>
    </asp:Content>
===================================================================================>
I am not new to working with the object datasource control in asp.net  but this has got me stumped. I gather for some reason the objectdatasource is not finding the method "UpdateMovies" with the identified signature above, but when I call on that method programatically, the signature is similar to what the error message is claimng it cannot find.

Help Please
ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry meant to say from your objectdatasource declaration in the aspx file so it looks like
<asp:ObjectDataSource ID="MovieDetails" runat="server" SelectMethod="GetMovieByID"
            TypeName="MeridianMoviesTableAdapters.MoviesTableAdapter" UpdateMethod="UpdateMovies">