Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
hello, i face problem and i cant understand it why it happen
i have listview which i use it to insert, update and delete with entity framework 3.5
every time i try to update or insert the following error showup
ObjectDataSource 'ODSLanguageLabels' could not find a non-generic method 'UpdateLangLBLs' that has parameters: LangID, LangGrpID, ResourceName, ResourceValue, Language.LangID, Languages_Groups.LangGrpID, ResourceID.

and here is my code for the class which has the methods
C#
public bool UpdateLangLBLs(int ResourceID,int LangID, int LangGrpID, string ResourceName, string ResourceValue )
        {
            bool result = false;
            if (ResourceID > 0 && LangID > 0 && LangGrpID > 0 && !string.IsNullOrEmpty(ResourceName) && !string.IsNullOrEmpty(ResourceValue) )
            {
                Languages_Labels updatedLangLab = null;
                using (decorEntities ctx = new decorEntities())
                {
                    updatedLangLab = ctx.Languages_Labels.Where(s => s.ResourceID == ResourceID).FirstOrDefault();
                    if (updatedLangLab != null)
                    {
                        Language selectedLang = ctx.Languages.Where(s => s.LangID == LangID).FirstOrDefault();
                        Languages_Groups selectedLangGrp = ctx.Languages_Groups.Where(s => s.LangGrpID == LangGrpID).FirstOrDefault();
                        updatedLangLab.Language.LangID = selectedLang.LangID;
                        updatedLangLab.Languages_Groups.LangGrpID = selectedLangGrp.LangGrpID;
                        updatedLangLab.ResourceName = ResourceName;
                        updatedLangLab.ResourceValue = ResourceValue;
                        
                        if (ctx.SaveChanges() > 0)
                        {
                            result = true;

                        }
                    }
                }
            }
            return result;
        }

public bool InsertLangLBLs(int langID, int langGrpID, string ResourceName, string ResourceValue)
        {
            bool result = false;
            if (langID > 0 && langGrpID > 0 && !string.IsNullOrEmpty(ResourceName) && !string.IsNullOrEmpty(ResourceValue))
            {
                using (decorEntities ctx = new decorEntities())
                {
                    Language seletctedLanguage = ctx.Languages.Where(s => s.LangID == langID).FirstOrDefault();
                    Languages_Groups selectedLangGrp = ctx.Languages_Groups.Where(g => g.LangGrpID == langGrpID).FirstOrDefault();
                    Languages_Labels newLangLabels = new Languages_Labels();
                    newLangLabels.ResourceName = ResourceName;
                    newLangLabels.ResourceValue = ResourceValue;
                    newLangLabels.Language = seletctedLanguage;
                    newLangLabels.Languages_Groups = selectedLangGrp;

                    ctx.AddToLanguages_Labels(newLangLabels);
                    if (ctx.SaveChanges() > 0)
                    {
                        result = true;
                    }
                }
            }
            return result;
        }

and this is my listview

ASP.NET
<asp:ListView ID="LVLangLabels" runat="server" EnableModelValidation="True" InsertItemPosition="LastItem"
                        DataSourceID="ODSLanguageLabels"  
                        DataKeyNames="ResourceID" 
                         
                        onitemcommand="LVLangLabels_ItemCommand">
                        <AlternatingItemTemplate>
                            <tr style="background-color: #FFF8DC;">
                                <td>
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                </td>
                                <td>
                                   <%-- <asp:Label ID="ResourceIDLabel" runat="server" Text='<%# Eval("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:Label ID="ResourceNameLabel" runat="server" Text='<%# Eval("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Eval("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="LanguageLabel" runat="server" Text='<%# Eval("Language.LangID") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Eval("Languages_Groups.LangGrpID") %>' />
                                </td>
                            </tr>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <tr style="background-color: #008A8C; color: #FFFFFF;">
                                <td>
                                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" onclick="UpdateButton_Click"/>
                                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                                </td>
                                <td>
                                    <%--<asp:TextBox ID="ResourceIDTextBox" runat="server" Text='<%# Bind("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceNameTextBox" runat="server" Text='<%# Bind("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceValueTextBox" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="LanguageTextBox" runat="server" Text='<%# Bind("Language.LangID") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="Languages_GroupsTextBox" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />
                                </td>
                            </tr>
                        </EditItemTemplate>
                        <EmptyDataTemplate>
                            <table  runat="server" style="background-color: #FFFFFF; border-collapse: collapse;
                                border-color: #999999; border-style: none; border-width: 1px;">
                                <tr>
                                    <td>
                                        No data was returned.
                                    </td>
                                </tr>
                            </table>
                        </EmptyDataTemplate>
                        <InsertItemTemplate>
                            <tr style="">
                                <td>
                                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
                                </td>
                                <td>
                                    <%--<asp:TextBox ID="ResourceIDTextBox" runat="server" Text='<%# Bind("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceNameTextBox" runat="server" Text='<%# Bind("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceValueTextBox" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="LanguageTextBox" runat="server" Text='<%# Bind("LangID") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="Languages_GroupsTextBox" runat="server" Text='<%# Bind("LangGrpID") %>' />
                                </td>
                            </tr>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <tr style="background-color: #DCDCDC; color: #000000;">
                                <td>
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                </td>
                                <td>
                                   <%-- <asp:Label ID="ResourceIDLabel" runat="server" Text='<%# Bind("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:Label ID="ResourceNameLabel" runat="server" Text='<%# Bind("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="LanguageLabel" runat="server" Text='<%# Bind("Language.LangID") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />
                                </td>
                            </tr>
                        </ItemTemplate>
                        <LayoutTemplate>
                            <table  runat="server">
                                <tr  runat="server">
                                    <td  runat="server">
                                        <table id="itemPlaceholderContainer"  runat="server" border="1" style="background-color: #FFFFFF;
                                            border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px;
                                            font-family: Verdana, Arial, Helvetica, sans-serif;">
                                            <tr  runat="server" style="background-color: #DCDCDC; color: #000000;">
                                                <th  runat="server">
                                                </th>
                                                <th  runat="server">
                                                    ResourceID
                                                </th>
                                                <th  runat="server">
                                                    ResourceName
                                                </th>
                                                <th  runat="server">
                                                    ResourceValue
                                                </th>
                                                <th  runat="server">
                                                    Language
                                                </th>
                                                <th  runat="server">
                                                    Languages_Groups
                                                </th>
                                            </tr>
                                            <tr id="itemPlaceholder"  runat="server">
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr  runat="server">
                                    <td  runat="server" style="text-align: center; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                                        color: #000000">
                                        <asp:DataPager ID="DataPager1" runat="server">
                                            <Fields>
                                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
                                            </Fields>
                                        </asp:DataPager>
                                    </td>
                                </tr>
                            </table>
                        </LayoutTemplate>
                        <SelectedItemTemplate>
                            <tr style="background-color: #008A8C; font-weight: bold; color: #FFFFFF;">
                                <td>
                                    <asp:Label ID="ResourceIDLabel" runat="server" Text='<%# Bind("ResourceID") %>' />
                                </td>
                                <td>
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                </td>
                                <td>
                                    <asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                    <td>
                                        <asp:Label ID="ResourceNameLabel" runat="server" Text='<%# Bind("ResourceName") %>' />
                                    </td>
                                    <td>
                                        <asp:Label ID="LanguageLabel" runat="server" Text='<%# Bind("Language.LangID") %>' />
                                    </td>
                                    <td>
                                        <asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />
                                    </td>
                                </td>
                            </tr>
                        </SelectedItemTemplate>
                    </asp:ListView>
                    <asp:ObjectDataSource ID="ODSLanguageLabels" runat="server" DeleteMethod="DeleteLanglbls"
                        InsertMethod="InsertLangLBLs" SelectMethod="GetAllLangLBLs" TypeName="DAL+BLLangLabels"
                        UpdateMethod="UpdateLangLBLs">
                        <DeleteParameters>
                            <asp:Parameter Name="ResourceID" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="langID" Type="Int32" />
                            <asp:Parameter Name="langGrpID" Type="Int32" />
                            <asp:Parameter Name="ResourceName" Type="String" />
                            <asp:Parameter Name="ResourceValue" Type="String" />
                        </InsertParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="ResourceID" Type="Int32" />
                            <asp:Parameter Name="LangID" Type="Int32" />
                            <asp:Parameter Name="LangGrpID" Type="Int32" />
                            <asp:Parameter Name="ResourceName" Type="String" />
                            <asp:Parameter Name="ResourceValue" Type="String" />
                        </UpdateParameters>
                    </asp:ObjectDataSource>

please anyone could explain to me why the Bind in the table and read the parameter as its?
like what i understand is .. the Object data source Expect parameter from the user and he cant find the same param name idk why :(
Posted

1 solution

From the code what I can make out is -
The Parameter names inside <updateparameters> and <insertparameters> tags should be same as that of the Parameter Name which you are binding in the label text.

For Example -
You have a label
ASP.NET
<asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Bind("ResourceValue") %>' />

And the parameter inside the <updateparameters> and <insertparameters> tags for the same label is -
ASP.NET
<asp:Parameter Name="ResourceValue" Type="String" />

So, from this it is clear that the parameter Name inside the "Bind()" method is same with the Name attribute value in Parameter tag, which is "ResourceValue".

So, assuming this logic you have some wrong value for some of the parameters.
They are-
1.
ASP.NET
<asp:Label ID="LanguageLabel" runat="server" Text='<%# Bind("Language.LangID") %>' />

for which you have parameter tag as -
ASP.NET
<asp:Parameter Name="langID" Type="Int32" />

which should be like -
ASP.NET
<asp:Parameter Name="Language.LangID" Type="Int32" />

And

2.
ASP.NET
<asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />

for which you have parameter tag as -
ASP.NET
<asp:Parameter Name="LangGrpID" Type="Int32" />

which should be like -
ASP.NET
<asp:Parameter Name="Languages_Groups.LangGrpID" Type="Int32" />


So, you have to make sure all the Parameter Names match.
Hope this solution helps.
Please let me know this helped you or not.
Thanks...
 
Share this answer
 
v2
Comments
Haitham tarek 30-Jul-12 14:15pm    
Well i have tried this before i send this question when i did this
* editing on the parameter name in the object data source it make error cuz its not the same name which i used in the method that update or insert..
and the parameter name can not be like XXX.XXX its Error Too :(
So you can use the name as "LangID" and "LangGrpID" only in the parameters and change these names inside the Bind() method to match. Like you can write Bind("LangID") and Bind("LangGrpID"). For this you also need to change the parameter names in the query/stored procedure.
Haitham tarek 30-Jul-12 14:44pm    
If i did this as u said >> i have Error which it means the entity famework cant see this parameter as "LangID" in the object Language
Look the problem is with the matching of names.
You have two entities - "Language and "Languages_Groups"
And u are getting values like "Language.LangID" and "Languages_Groups.LangGrpID".
Can u write something like this while executing the query...

Language.LangID as LangID
Languages_Groups.LangGrpID as LangGrpID

See, u have to get parameters as "LangID" and "LangGrpID".
So, try to find out a way how to do the same.
Otherwise I need to see all the codes with the queries also.
Let me know this idea helped u or not.
Haitham tarek 4-Aug-12 8:52am    
it doesn't work too :( but i did it with the hard way like
i make it separated method out the list view to do this 2 functions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900