本文介绍了找不到具有参数的非泛型方法“删除"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用绑定到ObjectDataSource的Gridview控件时,这是从.net返回的字符串.ObjectDataSource绑定到.net数据集中的tableAdapter.

That's a string returned from .net when using a Gridview control bound to an ObjectDataSource. The ObjectDataSource is bound to a tableAdapter in a .net DataSet.

数据集具有一个自动生成的表适配器,并已在我的数据库中创建了更新,插入,选择和删除存储的过程.

The dataset has a table adapter that is auto generated and has created an update, insert, select and delete stored proc in my database.

网格现在正在使用此源,并且应该允许插入,更新和删除.

The grid is now using this source and should allow insert, updates and deletes.

插入和更新有效,但删除明确显示错误

Insert and updates are working but the delete specifically gives the error

ObjectDataSource'odsCustomerAliases'找不到具有以下参数的非通用方法'Delete':CustomerAlias,original_CustomerAlias.

ObjectDataSource 'odsCustomerAliases' could not find a non-generic method 'Delete' that has parameters: CustomerAlias, original_CustomerAlias.

虽然我可以阅读该错误,但我已经尝试了很多方法,但无法使它正常工作.我真的看不到如何期望参数'original_CustomerAlias'

Whilst I can read the error I have tried a number of things and cannot get this to work. I can't really see how it's expecting a parameter 'original_CustomerAlias'

我可以确认此参数在proc中不存在.

I can confirm this parameter does not exist in the proc.

这里有些代码片段似乎是正确的.

Here are some code snippets which seem to be correct.

<asp:ObjectDataSource ID="odsCustomerAliases" runat="server" DeleteMethod="Delete"
                InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
                TypeName="SLRDataAccess.dsTableAdapters.CustomerAliasesTableAdapter" UpdateMethod="Update">
                <DeleteParameters>
                    <asp:Parameter Name="CustomerAlias" Type="String" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="original_CustomerAlias" Type="String" />
                    <asp:Parameter Name="CustomerAlias" Type="String" />
                </UpdateParameters>
                <SelectParameters>
                    <asp:SessionParameter Name="CustomerID" SessionField="CustomerID" Type="Int32" />
                </SelectParameters>
                <InsertParameters>
                    <asp:Parameter Name="CustomerAlias" Type="String" />
                    <asp:Parameter Name="CustomerID" Type="Int32" />
                </InsertParameters>
            </asp:ObjectDataSource>

自动生成的数据集中的部分.

The section from the auto generated dataset.

<DeleteCommand>
              <DbCommand CommandType="StoredProcedure" ModifiedByUser="False">
                <CommandText>dbo.usp_DeleteCustomerAlias</CommandText>
                <Parameters>
                  <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="ReturnValue" ParameterName="@RETURN_VALUE" Precision="10" ProviderType="Int" Scale="0" Size="4" SourceColumnNullMapping="False" SourceVersion="Current">
                  </Parameter>
                  <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@CustomerAlias" Precision="0" ProviderType="VarChar" Scale="0" Size="100" SourceColumn="CustomerAlias" SourceColumnNullMapping="False" SourceVersion="Current">
                  </Parameter>
                </Parameters>
              </DbCommand>
            </DeleteCommand>

设计人员的最终代码段我认为实际上并不相关,但是...

The final code snippet from the designer which I imagine is not actually relevant but...

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
     Global.System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter"),  _
     Global.System.ComponentModel.DataObjectMethodAttribute(Global.System.ComponentModel.DataObjectMethodType.Delete, true)>  _
    Public Overloads Overridable Function Delete(ByVal CustomerAlias As String) As Integer
        If (CustomerAlias Is Nothing) Then
            Me.Adapter.DeleteCommand.Parameters(1).Value = Global.System.DBNull.Value
        Else
            Me.Adapter.DeleteCommand.Parameters(1).Value = CType(CustomerAlias,String)
        End If
        Dim previousConnectionState As Global.System.Data.ConnectionState = Me.Adapter.DeleteCommand.Connection.State
        If ((Me.Adapter.DeleteCommand.Connection.State And Global.System.Data.ConnectionState.Open)  _
                    <> Global.System.Data.ConnectionState.Open) Then
            Me.Adapter.DeleteCommand.Connection.Open
        End If
        Try
            Dim returnValue As Integer = Me.Adapter.DeleteCommand.ExecuteNonQuery
            Return returnValue
        Finally
            If (previousConnectionState = Global.System.Data.ConnectionState.Closed) Then
                Me.Adapter.DeleteCommand.Connection.Close
            End If
        End Try
    End Function

推荐答案

属性OldValuesParameterFormatString存在问题-强制方法接受2个参数.只需删除它的属性即可.

You have a problem with attribute OldValuesParameterFormatString - that forces method to accept 2 arguments. Just remove it attribute at all.

这篇关于找不到具有参数的非泛型方法“删除"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:51