问题
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>
回答1:
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:
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
回答2:
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