Hello
I have a stored procedure witch should return products from a specific table:
ALTER PROCEDURE [dbo].[Browse_selectproduse]
-- Add the parameters for the stored procedure here
@SqlCommand NVARCHAR(3000),
@PageNumber TINYINT,
@ProductsPerPage TINYINT,
@HowManyResults SMALLINT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET nocount ON;
-- Insert statements for procedure here
DECLARE @Products TABLE(
rownumber SMALLINT IDENTITY ( 1 , 1 ) NOT NULL,
productid INT,
username NVARCHAR(255),
name VARCHAR(70),
DESCRIPTION VARCHAR(2000),
image1 VARCHAR(200)
)
INSERT INTO @Products
EXEC @SqlCommand
SELECT @HowManyResults = Count(* )
FROM @Products
SELECT [ProductID],
[UserName],
[Name],
[Description],
[Image1]
FROM @Products
WHERE rownumber BETWEEN (@PageNumber - 1) * @ProductsPerPage + 1 AND @PageNumber * @ProductsPerPage
END
Normally, i should replace EXEC @SqlCommand with a SELECT statement that inserts into @Products table the required products.
In code-behind, i am constructing SqlCommand string witch is exactly that SELECT statement, but when i am trying to execute database command i get the folowing error:
The name 'SELECT p.[ProductID], p.[UserName], p.[Name], p.[Description],p.[Image1] FROM [Product] AS p INNER JOIN [ProductSscat] AS s ON p.[ProductID] = s.[ProductID] WHERE s.[SubsubcategoryID] = 502 ORDER BY p.[DateAdded] DESC' is not a valid identifier.
Line 785: comm.Connection.Open();
Line 786: // Execute the command and save the results in a DataTable
Line 787: DbDataReader reader = comm.ExecuteReader();
Line 788: table = new DataTable();
Line 789: table.Load(reader);
is there any way to resolve my problem?
Thank you