ObjectDataSource'ObjectDataSource1'找不到非通用方法Update

ObjectDataSource 'ObjectDataSource1' could not find a non-generic method Update
2021-03-07
  •  译文(汉语)
  •  原文(英语)

到目前为止,我都尝试过类似的问题,并且每次都遇到此错误.请帮助!

静态方法

[DataObjectMethod(DataObjectMethodType.Update)]
public static void updateCustomer(int CustomerID, string firstname, string lastname, string email, int AccountNum)
{

    SqlConnection connection = new SqlConnection(getConnectionString());

    connection.Open();

    SqlCommand command = new SqlCommand("sp_updateCustomer", connection);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.AddWithValue("@Cust_Id", CustomerID);
    command.Parameters.AddWithValue("@Cust_Fname", firstname);
    command.Parameters.AddWithValue("@Cust_Lname", lastname);
    command.Parameters.AddWithValue("@Cust_Email", email);
    command.Parameters.AddWithValue("@Bank_Account_num", AccountNum);




    command.ExecuteNonQuery();

    connection.Close();
}

网格视图

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="viewAllCustomer" TypeName="BusinessLogic" UpdateMethod="updateCustomer" >
    <UpdateParameters>
        <asp:Parameter Name="CustomerID" Type="Int32" />
        <asp:Parameter Name="firstname" Type="String" />
        <asp:Parameter Name="lastname" Type="String" />
        <asp:Parameter Name="email" Type="String" />
        <asp:Parameter Name="AccountNum" Type="Int32" />
    </UpdateParameters>

速聊1:
你在哪里申报updateCustomer?
速聊2:
您能否向我们展示带有名称空间以及selectmethod和updatemethod的整个类结构?
速聊3:
确保您的类名称和名称空间
解决过程1

使用VS-2012 Express for WEB,我也为此感到困惑,并且发现参数名称必须在四个地方匹配-类型数据集设计器(xsd),BLL类更新功能,aspx-designer "配置数据源"和aspx源文件.

首先,通过选择"将异常详细信息复制到剪贴板",在错误弹出时保存错误消息的副本,以便可以在NOTEPAD中进行引用.将这些参数视为错误:请注意,当EMAIL参数被两个*包围时,应为粗体.

  Message=ObjectDataSource 'ODS_LOGIN_DETAILS' could not find a non-generic method 
'UpdateFromDetailsView' that has parameters: 
    original_UID_LOGIN, original_UID_CONTACT, UID_USER_TYPE, TXT_USERNAME,
    TXT_PASSWORD, BOOL_IS_ACTIVE, DT_END, cFirstName, cLastName, 
    cCONTACTTITLE, original_cTXT_PHONE, **cCONTACT_EMAIL**.

然后,将错误消息中的参数列表与代码中的以下位置进行比较:

  1. 数据源参数的aspx页(例如...)

    <UpdateParameters>
    <asp:Parameter Name="original_UID_LOGIN" Type="Int32" />
    <asp:Parameter Name="original_UID_CONTACT" Type="Int32" />
    <asp:Parameter Name="UID_USER_TYPE" Type="Int32" />
    <asp:Parameter Name="TXT_USERNAME" Type="String" />
    <asp:Parameter Name="TXT_PASSWORD" Type="String" />
    <asp:Parameter Name="BOOL_IS_ACTIVE" Type="Boolean" />
    <asp:Parameter Name="DT_END" Type="DateTime" />
    <asp:Parameter Name="cFirstName" Type="String" />
    <asp:Parameter Name="cLastName" Type="String" />
    <asp:Parameter Name="cCONTACTTITLE" Type="String" />
    <asp:Parameter Name="original_cTXT_PHONE" Type="String" />
    <asp:Parameter Name="**cCONTACT_EMAIL**" Type="String" />
    

现在比较ObjectDataSource UPDATE方法的参数列表:

Public Function UpdateFromDetailsView(
   ByVal original_UID_LOGIN As Int32,
   ByVal original_UID_CONTACT As Int32,
   ByVal UID_USER_TYPE As Int32,
   ByVal TXT_USERNAME As String,
   ByVal TXT_PASSWORD As String,
   ByVal BOOL_IS_ACTIVE As Boolean,
   ByVal DT_END As Date,
   ByVal cFirstName As String,
   ByVal cLastName As String,
   ByVal cCONTACTTITLE As String,
   ByVal original_cTXT_PHONE As String,
   ByVal **CONTACT_EMAIL** As String
 ) As Boolean

最后,将参数与强类型数据集功能进行比较:

iRet = Adapter.UpdateFromDetailsView(
   original_UID_LOGIN,
   original_UID_CONTACT,
   UID_USER_TYPE,
   TXT_USERNAME,
   TXT_PASSWORD,
   BOOL_IS_ACTIVE,
   DT_END,
   cFirstName,
   cLastName,
   cCONTACTTITLE,
   original_cTXT_PHONE,
   **CONTACT_EMAIL**)

您应该注意到EMAIL参数存在许多差异,并且所有这些引用都必须具有相同的参数名称.

当您"重建解决方案"时,类型化的数据集将被更新,并且BLL类将被更新,但是aspx中的ObjectDataSource不会被更新.重建解决方案后,您需要在aspx-designer页面上"配置数据源".

在此示例中,BLL类需要包含"cCONTACT_EMAIL"作为参数并传递给适配器函数.

我希望这会有所帮助...谢谢...约翰

解决过程2

从ObjectDataSource,我会说是的,您使用的TypeName错误.在MSDN文章中,它是指托管方法的类,而不是方法的返回类型.

尝试将TypeName ="System.Data.DataTable"更改为TypeName ="BusinessLogic"

请参考http://csharpdotnetfreak.blogspot.com/2009/06/gridview-objectdatasource-insert-update.html

i tried every solution so far with this similar problem and i get this error everytime. Plz Help!!

static method

[DataObjectMethod(DataObjectMethodType.Update)]
public static void updateCustomer(int CustomerID, string firstname, string lastname, string email, int AccountNum)
{

    SqlConnection connection = new SqlConnection(getConnectionString());

    connection.Open();

    SqlCommand command = new SqlCommand("sp_updateCustomer", connection);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.AddWithValue("@Cust_Id", CustomerID);
    command.Parameters.AddWithValue("@Cust_Fname", firstname);
    command.Parameters.AddWithValue("@Cust_Lname", lastname);
    command.Parameters.AddWithValue("@Cust_Email", email);
    command.Parameters.AddWithValue("@Bank_Account_num", AccountNum);




    command.ExecuteNonQuery();

    connection.Close();
}

GridView

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="viewAllCustomer" TypeName="BusinessLogic" UpdateMethod="updateCustomer" >
    <UpdateParameters>
        <asp:Parameter Name="CustomerID" Type="Int32" />
        <asp:Parameter Name="firstname" Type="String" />
        <asp:Parameter Name="lastname" Type="String" />
        <asp:Parameter Name="email" Type="String" />
        <asp:Parameter Name="AccountNum" Type="Int32" />
    </UpdateParameters>

Talk1:
Where are you declare updateCustomer?
Talk2:
could you show us the entire class structure with the namespace and the selectmethod and updatemethod?
Talk3:
make sure of your class name and namespace
Solutions1

Using VS-2012 Express for WEB, I struggled with this too, and have found that there are four places that the parameter names must match - typed-data-set designer (xsd), BLL-class update-function, aspx-designer to 'Configure Data Source' and the aspx-source file.

First, save a copy of the error message when the error popups up by selecting "Copy exception detail to the clipboard" so you can refer to it in NOTEPAD. See these parameters as the error: Notice that the EMAIL parameter should be BOLD when surrounded by two *.

  Message=ObjectDataSource 'ODS_LOGIN_DETAILS' could not find a non-generic method 
'UpdateFromDetailsView' that has parameters: 
    original_UID_LOGIN, original_UID_CONTACT, UID_USER_TYPE, TXT_USERNAME,
    TXT_PASSWORD, BOOL_IS_ACTIVE, DT_END, cFirstName, cLastName, 
    cCONTACTTITLE, original_cTXT_PHONE, **cCONTACT_EMAIL**.

Then, compare the list of parameters in the error-message to these locations in your code:

  1. The aspx page of the datasource parameters (eg...)

    <UpdateParameters>
    <asp:Parameter Name="original_UID_LOGIN" Type="Int32" />
    <asp:Parameter Name="original_UID_CONTACT" Type="Int32" />
    <asp:Parameter Name="UID_USER_TYPE" Type="Int32" />
    <asp:Parameter Name="TXT_USERNAME" Type="String" />
    <asp:Parameter Name="TXT_PASSWORD" Type="String" />
    <asp:Parameter Name="BOOL_IS_ACTIVE" Type="Boolean" />
    <asp:Parameter Name="DT_END" Type="DateTime" />
    <asp:Parameter Name="cFirstName" Type="String" />
    <asp:Parameter Name="cLastName" Type="String" />
    <asp:Parameter Name="cCONTACTTITLE" Type="String" />
    <asp:Parameter Name="original_cTXT_PHONE" Type="String" />
    <asp:Parameter Name="**cCONTACT_EMAIL**" Type="String" />
    

Now compare the parameter list of the ObjectDataSource UPDATE-method:

Public Function UpdateFromDetailsView(
   ByVal original_UID_LOGIN As Int32,
   ByVal original_UID_CONTACT As Int32,
   ByVal UID_USER_TYPE As Int32,
   ByVal TXT_USERNAME As String,
   ByVal TXT_PASSWORD As String,
   ByVal BOOL_IS_ACTIVE As Boolean,
   ByVal DT_END As Date,
   ByVal cFirstName As String,
   ByVal cLastName As String,
   ByVal cCONTACTTITLE As String,
   ByVal original_cTXT_PHONE As String,
   ByVal **CONTACT_EMAIL** As String
 ) As Boolean

And, finally, compare the parameters to the strongly-typed-dataset function:

iRet = Adapter.UpdateFromDetailsView(
   original_UID_LOGIN,
   original_UID_CONTACT,
   UID_USER_TYPE,
   TXT_USERNAME,
   TXT_PASSWORD,
   BOOL_IS_ACTIVE,
   DT_END,
   cFirstName,
   cLastName,
   cCONTACTTITLE,
   original_cTXT_PHONE,
   **CONTACT_EMAIL**)

You should notice that there are a number of differences for the EMAIL parameter, and ALL of these references need to have the same parameter-name.

When you "Rebuild Solution", the typed-data-set will be updated, and the BLL-class will be updated, but NOT the ObjectDataSource in the aspx. You would need to "Configure Data Source" on the aspx-designer page after rebuilding the solution.

In this example, the BLL-class needed to contain a 'cCONTACT_EMAIL' as the parameter and passed to the adapter function.

I hope this helps...thanks...John

Solutions2

From the ObjectDataSource, I would say yes you're using TypeName wrong. In the MSDN article, it refers to the class which hosts the method, not the return type of the method.

Try changing TypeName="System.Data.DataTable" to TypeName="BusinessLogic"

please refer http://csharpdotnetfreak.blogspot.com/2009/06/gridview-objectdatasource-insert-update.html

转载于:https://stackoverflow.com/questions/23054334/objectdatasource-objectdatasource1-could-not-find-a-non-generic-method-update

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入