ObjectDataSource INSERT发现查找非泛型方法。 [英] ObjectDataSource INSERT issues finding non-generic method.

查看:51
本文介绍了ObjectDataSource INSERT发现查找非泛型方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个基本的ASP.NET Web表单,该表单使用ObjectDataSource将数据插入数据库。最初,它是使用SQLDataSource编写的(后面带有所需的代码)并且像魅力一样工作。由于网站的其余部分使用XSD和ObjectDataSources,我正在尝试将其转换为ObjectDataSource。完成所有必需的编码后,在测试期间,我收到错误:



 ObjectDataSource'odsRequest'找不到非泛型方法'InsertRequest',包含参数:wrName,customerID,staffID,priority,status,genCom,submitDt,targetDt,wrType,@ WRName,@ CustomerID,@ Standid,@ Priority,@ Status,@ GenCom,@ SubmitDt,@ TargetDt, @WRType。





过去我遇到过类似的问题,并且能够快速修复它们。我花了几个小时看这个并且很难​​过。



以下是我正在使用的各个代码部分:



SQL QUERY

  INSERT   INTO  WorkReq(WRName,CustomerID,StaffID,优先级,状态,GenCom,SubmitDt,TargetDt,WRType)
VALUES @ WRName @ CustomerID @ StaffID @ Priority @ Status @ GenCom @ SubmitDt @ TargetDt @ WRType );
SELECT SCOPE_IDENTITY ();





ASP ObjectDataSource

 <   asp:ObjectDataSource     ID   =  odsRequest    runat   =  server  

InsertMethod = InsertRequest TypeName = WorkReqBLL >
< InsertParameters >
< asp:参数 名称 = wrName 类型 = 字符串 / >
< asp:参数 N ame = customerID 类型 = Int32 / >
< asp:参数 名称 = staffID 类型 = Int32 / >
< asp:参数 名称 = priority 类型 = < span class =code-keyword>字符串 / >
< asp:参数 名称 = status 类型 = 字符串 / >
< asp:参数 名称 = genCom 类型 = 字符串 / >
< asp:参数 名称 = submitDt 类型 = DateTime / >
< asp:参数 Name = targetDt 类型 = DateTime / >
< asp:参数 名称 = wrType 类型 = 字符串 / >
< / InsertParameters >
< / asp:ObjectDataSource >





VB代码背后

 受保护  Sub  odsRequest_Inserting( ByVal  sender 作为 对象 ByVal  e  As  System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs)句柄 odsRequest.Inserting 

如果 ddlCourse.SelectedValue = 0 然后
e.InputParam eters( @ WRName)= txtSummary.Text
Else
e.InputParameters( @ WRName)= txtSummary.Text& - & ddlCourse.SelectedItem.Text
结束 如果

e.InputParameters ( @ CustomerID)= GetUserID()
e.InputParameters( @ StaffID)= 35000
e.InputParameters( @ Priority)= Medium
e.InputParameters( @ Status)= O
e.InputParameters( @ GenCom)= txtExplanation .Text.Replace(Environment.NewLine,vbNewLine)
e.InputParameters( @ SubmitDt)= DateTime.Now
e.InputParameters( < span class =code-string> @ TargetDt)= DateTime.ParseExact(txtTarget.Text& 08:00 AM MM / dd / yyyy HH:mm tt Nothing
e.InputParameters(< span class =code-string> @ WRType)= 外部

结束 Sub







VB BLL

< System.ComponentModel.DataObjectMethodAttribute _ 
(System.ComponentModel.DataObjectMethodType.Insert, False )> _
公共 功能 InsertRequest(_
ByVal wrName 作为 字符串,_
ByVal customerID As Nullable( Of 整数),_
ByVal staffID As Nullable( 整数),_
ByVal 优先级作为 字符串,_
ByVal status 作为 字符串,_
ByVal < /跨度> genCom 作为 字符串,_
ByVal submitDt 作为 Nullable( 日期 ),_
ByVal targetDt As Nullable( 日期),_
ByVal wrType 作为 字符串作为 布尔值

' 不需要WRID,因为它是数据库中的标识。
Dim 个请求作为 ITEX.WorkReqDataTable()
< span class =code-keyword> Dim
request As ITEX.WorkReqRow = requests.NewWorkReqRow()

request.WrName = wrName

request.Priority = priority
request.Status = status

如果 customerID.HasValue customerID.Value = 0 < span class =code-keyword>然后
request.SetCustomerIDNull()
否则
request.CustomerID = customerID.Value
结束 如果

如果 staffID.HasValue staffID.Value = 0 然后
request.SetStaffIDNull()
否则
request.StaffID = staffID.Value
结束 如果

request.SubmitDt = submitDt.Value

如果 targetDt.HasValue 然后
request.SetTargetDtNull()
否则
request.TargetDt = targetDt.Value
结束 如果

request.WrType = wrType

requests.AddWorkReqRow(request)
Dim rowsAffected < span class =code-keyword> As Integer = Adapter.Update(requests)

返回 rowsAffected = 1
结束 函数

解决方案

我认为ObjectDataSource中的参数区分大小写。案件不符合。 e.InputParameters(@ WRName)<> < asp:parameter name =wrNametype =Stringxmlns:asp =#unknown>所以代码正在寻找一种不同的插入方法


我在一张大脸掌之后想出来了。问题是在我的代码隐藏中,我仍然在参数名称前面有@。我忘了在ObjectDataSource中,不需要@,而是SQLDataSource。

 受保护  Sub  odsRequest_Inserting( ByVal  sender  As  < span class =code-keyword> Object , ByVal  e  As  System.Web。 UI.WebControls.ObjectDataSourceMethodEventArgs)句柄 odsRequest.Inserting 

如果 ddlCourse.SelectedValue = 0 然后
e.InputParameters( WRName)= txtSummary.Text
否则
e。 InputParameters( WRName)= txtSummary.Text& - & ddlCourse.SelectedItem.Text
结束 如果

e.InputParameters ( CustomerID)= GetUserID()
e.InputParameters( StaffID)= 35000
e.InputParameters( Priority)= Medium
e.InputParameters( 状态)= O
e.InputParameters( GenCom)= txtExplanation.Text.Replace( Environment.NewLine,vbNewLine)
e.InputParameters( SubmitDt)= DateTime.Now
e.InputParameters( TargetDt)= DateTime.ParseExact(txtTarget.Text& 08:00 AM MM / dd / yyyy HH:mm tt Nothing
e.InputParameters(< span class =code-string>
WRType)= 外部

结束 Sub


I'm working on a basic ASP.NET web form that uses an ObjectDataSource to insert data into a database. Originally, it was scripted using a SQLDataSource (with the required code behind) and worked like a charm. Since the rest of the site uses an XSD and ObjectDataSources, I'm trying to convert it to an ObjectDataSource. After all of the required coding, during testing, I'm recieving the error:

ObjectDataSource 'odsRequest' could not find a non-generic method 'InsertRequest' that has parameters: wrName, customerID, staffID, priority, status, genCom, submitDt, targetDt, wrType, @WRName, @CustomerID, @StaffID, @Priority, @Status, @GenCom, @SubmitDt, @TargetDt, @WRType.



I've encountered simular issues in the past and have been able to quickly fix them. I've spent a couple hours looking at this and am stumped.

Here are the various sections of code I am using:

SQL QUERY

INSERT INTO WorkReq (WRName, CustomerID, StaffID, Priority, Status, GenCom, SubmitDt, TargetDt, WRType)
VALUES (@WRName, @CustomerID, @StaffID, @Priority, @Status, @GenCom, @SubmitDt, @TargetDt, @WRType);
SELECT SCOPE_IDENTITY();



ASP ObjectDataSource

<asp:ObjectDataSource ID="odsRequest" runat="server"

    InsertMethod="InsertRequest" TypeName="WorkReqBLL">
    <InsertParameters>
        <asp:Parameter Name="wrName" Type="String" />
        <asp:Parameter Name="customerID" Type="Int32" />
        <asp:Parameter Name="staffID" Type="Int32" />
        <asp:Parameter Name="priority" Type="String" />
        <asp:Parameter Name="status" Type="String" />
        <asp:Parameter Name="genCom" Type="String" />
        <asp:Parameter Name="submitDt" Type="DateTime" />
        <asp:Parameter Name="targetDt" Type="DateTime" />
        <asp:Parameter Name="wrType" Type="String" />
    </InsertParameters>
</asp:ObjectDataSource>



VB Code Behind

Protected Sub odsRequest_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles odsRequest.Inserting

    If ddlCourse.SelectedValue = 0 Then
        e.InputParameters("@WRName") = txtSummary.Text
    Else
        e.InputParameters("@WRName") = txtSummary.Text & " - " & ddlCourse.SelectedItem.Text
    End If

    e.InputParameters("@CustomerID") = GetUserID()
    e.InputParameters("@StaffID") = "35000"
    e.InputParameters("@Priority") = "Medium"
    e.InputParameters("@Status") = "O"
    e.InputParameters("@GenCom") = txtExplanation.Text.Replace(Environment.NewLine, vbNewLine)
    e.InputParameters("@SubmitDt") = DateTime.Now
    e.InputParameters("@TargetDt") = DateTime.ParseExact(txtTarget.Text & " 08:00 AM", "MM/dd/yyyy HH:mm tt", Nothing)
    e.InputParameters("@WRType") = "External"

End Sub




VB BLL

<System.ComponentModel.DataObjectMethodAttribute _
 (System.ComponentModel.DataObjectMethodType.Insert, False)> _
 Public Function InsertRequest( _
             ByVal wrName As String, _
             ByVal customerID As Nullable(Of Integer), _
             ByVal staffID As Nullable(Of Integer), _
             ByVal priority As String, _
             ByVal status As String, _
             ByVal genCom As String, _
             ByVal submitDt As Nullable(Of Date), _
             ByVal targetDt As Nullable(Of Date), _
             ByVal wrType As String) As Boolean

     'No WRID needed because it's an identity in the DB.
     Dim requests As New ITEX.WorkReqDataTable()
     Dim request As ITEX.WorkReqRow = requests.NewWorkReqRow()

     request.WrName = wrName

     request.Priority = priority
     request.Status = status

     If Not customerID.HasValue Or customerID.Value = 0 Then
         request.SetCustomerIDNull()
     Else
         request.CustomerID = customerID.Value
     End If

     If Not staffID.HasValue Or staffID.Value = 0 Then
         request.SetStaffIDNull()
     Else
         request.StaffID = staffID.Value
     End If

     request.SubmitDt = submitDt.Value

     If Not targetDt.HasValue Then
         request.SetTargetDtNull()
     Else
         request.TargetDt = targetDt.Value
     End If

     request.WrType = wrType

     requests.AddWorkReqRow(request)
     Dim rowsAffected As Integer = Adapter.Update(requests)

     Return rowsAffected = 1
 End Function

解决方案

I believe parameters in a ObjectDataSource are case sensitive. The case does not match. e.InputParameters("@WRName") <> <asp:parameter name="wrName" type="String" xmlns:asp="#unknown"> So the code is looking for a diffrent insert method


I figured this out after a big face palm. The problem was that in my code-behind, I still had the @ before the parameter name. I forgot that in an ObjectDataSource, the @ isn't needed, but is for a SQLDataSource.

Protected Sub odsRequest_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles odsRequest.Inserting

    If ddlCourse.SelectedValue = 0 Then
        e.InputParameters("WRName") = txtSummary.Text
    Else
        e.InputParameters("WRName") = txtSummary.Text & " - " & ddlCourse.SelectedItem.Text
    End If

    e.InputParameters("CustomerID") = GetUserID()
    e.InputParameters("StaffID") = "35000"
    e.InputParameters("Priority") = "Medium"
    e.InputParameters("Status") = "O"
    e.InputParameters("GenCom") = txtExplanation.Text.Replace(Environment.NewLine, vbNewLine)
    e.InputParameters("SubmitDt") = DateTime.Now
    e.InputParameters("TargetDt") = DateTime.ParseExact(txtTarget.Text & " 08:00 AM", "MM/dd/yyyy HH:mm tt", Nothing)
    e.InputParameters("WRType") = "External"

End Sub


这篇关于ObjectDataSource INSERT发现查找非泛型方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆