Hi All,I have a stored procedure which accepts about 2 parameters, I am including a sample for the same below.
=================================================================Code:
CREATE PROCEDURE App_Products_GetList
@Id NUMERIC(18,0) = NULL,
@Name VARCHAR(50) = NULL
AS BEGIN
SELECT
[Id]
,[Name]
FROM
[Products]
WHERE
(([Id] = @Id AND @Id IS NOT NULL) OR @Id IS NULL) AND
(([Name] LIKE @Name AND @Name IS NOT NULL) OR @Name IS NULL)
END
Now, I want to pass
null values to both @Id and @Name in certain cases. For this I tried the following.
Code:
IQuery iQuery = NHibernateHelper.GetCurrentSession().GetNamedQuery("App_Products_GetList_1");
iQuery.SetString("Id", "NULL");
iQuery.SetString("Name", "NULL");
IList<Product> ilist_1 = iQuery.List<Product>() as List<Product>;
=================================================================At this point I am getting an error. [could not execute query], with the underlying details
Error converting data type nvarchar to numeric.
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: Error converting data type nvarchar to numeric.
Source Error:
IList<Product> ilist_1 = iQuery.List<Product>() as List<Product>;
=================================================================I checked the profiler code which outputs the content as,
Code:
exec sp_executesql N'exec [App_Products_GetList] @p0,@p1', N'@p0 nvarchar(4),@p1 nvarchar(12)', @p0=N'NULL',@p1=N'NULL'
Here too the error message which I have encountered is: Error converting data type nvarchar to numeric.
=================================================================I would like to know, how to pass NULL values to the stored procedure through the above mentioned call.Regards,
Sougandh Pavithran