Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
SQL
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
XML
<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
VB
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
VB
<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
Posted

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
 
Share this answer
 
Comments
Michael-John Komidar 25-Feb-15 14:51pm    
I made sure everything was cased the same and still go the same 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 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.
VB
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
 
Share this answer
 

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