[Solved] ASP.Net RDLC Error: Procedure or function expects parameter which was not supplied

makumbi
 
on Mar 16, 2022 06:40 AM
638 Views

error while generating report with parameters in my report design i have added the following parameters  class, intake, points.

Procedure or function 'Runclass2print2' expects parameter '@c', which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Procedure or function 'Runclass2print2' expects parameter '@c', which was not supplied.

Source Error:


Line 47:             Dim adaptor As New SqlDataAdapter(cmd)
Line 48:             adaptor.SelectCommand = cmd
Line 49:             adaptor.Fill(ResultsTable)
Line 50:         'Catch ex As Exception
Line 51:         'MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])

my storedprocedure

PROCEDURE [dbo].[Runclass2print2] @c nvarchar(50),@it nvarchar(50),@k float AS
SELECT sst,science,cases,avgs2,account,Emarksdate,status, taken, fno, upper(Name) as name, student.Class, student.Intake, student.Category, student.Maths, student.Eng, student.date, [maths]+[eng]/2 AS Average, student.Username,avgs,pname,contact,username,usernamemarks,Left([Name],1) as Letter,Groups
FROM student
WHERE (((student.Class)=@c) AND ((student.Intake)=@it)) and  (status IS NULL)  and (Maths IS NOT NULL) AND (Eng IS NOT NULL)   and  (avgs2 < @k)
ORDER BY class, student.Name, [maths]+[eng]/2 DESC;

 my form display repor webpage

Imports System.Configuration
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms

Public Class DisplayReport
    Inherits System.Web.UI.Page
    Dim con As String = ConfigurationManager.ConnectionStrings("INTERVIEWSConnectionString").ConnectionString

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            BindReport()
            ReportViewer1.LocalReport.Refresh()
        End If
    End Sub

    Public Sub BindReport()
        ' Try
        Dim ResultsTable As New DataTable()
        Dim conn As New SqlConnection(con)

        ReportViewer1.ProcessingMode = ProcessingMode.Local
        Dim dt As DataTable = GetSPResult()
        ReportViewer1.Visible = True
        ' ReportViewer1.LocalReport.ReportPath = "Report1.rdlc"
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/ClassList.rdlc")
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", dt))
    End Sub


    Private Function GetSPResult() As DataTable

        Dim ResultsTable As New DataTable()
        Dim conn As New SqlConnection(con)
        ' ProviderName = "System.Data.SqlClient");
        'Try
        Dim classr As String = Request.QueryString("class")
            Dim intake As String = Request.QueryString("intake")
            Dim points As String = Request.QueryString("point")
            Dim cmd As New SqlCommand("Runclass2print2", conn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@c", classr)
            cmd.Parameters.AddWithValue("@it", intake)
            cmd.Parameters.AddWithValue("@k", points)
            conn.Open()
            'cmd.ExecuteNonQuery();
            Dim adaptor As New SqlDataAdapter(cmd)
            adaptor.SelectCommand = cmd
            adaptor.Fill(ResultsTable)
        'Catch ex As Exception
        'MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        'End Try
        Return ResultsTable
    End Function
End Class

this is how i pass the parameters from the click button

Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim named As String = DropDownList2.SelectedValue
    Dim intake As String = DropDownList1.SelectedValue
    Dim point As Boolean = CheckBox2.Checked
    Response.Redirect(String.Format("~/Reports/DisplayReport.aspx?class={0}&intake={1}&point={2}", named, intake, point))
End Sub

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
makumbi
 
on Mar 16, 2022 07:16 AM

Thank you very much i solved it by removing the parameters i had inserted in the report design.