Below is the stored procedure:
ALTER PROCEDURE Retrieve_Data
@noOfRecords INTEGER
AS
BEGIN TRY
SET NOCOUNT ON;
SELECT TOP(@noOfRecords) studentId
FROM Student;
END TRY
BEGIN CATCH
RETURN -101
END CATCH
RETURN 0
Below is the C# code:
DataSet ds = null;
try
{
using (SqlConnection conn = new SqlConnection(ConfigurationSettings.ConectionString))
{
using (SqlDataAdapter da = new SqlDataAdapter())
{
da.SelectCommand = new SqlCommand(storedProcedureName, conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter param= new SqlParameter("@noOfRecords", SqlDbType.Int);
param.Value = 10;
da.SelectCommand.Parameters.Add(param);
ds = new DataSet();
da.Fill(ds, "result");
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
return ds;
}
}
}
While executing the code I am getting a SQL exception:
Procedure Retrieve_Data has no parameters and arguments were supplied
2条答案
按热度按时间xkftehaa1#
The syntax of your stored procedure is incorrect. You need to provide the input parameters inside brackets
Also you can try to clear your parameters inside the code:
6ju8rftf2#
Change your stored procedure and wrap with
BEGIN ... END
Second thing about ordering table
Student
usingORDER BY ...