I have string variable in c#
String Condition = " And LoginName like ''%"+txtLoginName.text+"%''";
I pass this condition variable to a stored procedure like this:
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "GetAllUserMasterBySearch";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Condition ", Condition );
And my stored procedure is here:
create PROCEDURE [dbo].[GetAllUserMasterBySearch] (
@Condition nvarchar(max)
)
as
declare @Query nvarchar(max)
set @Query = 'SELECT
[UserMasterId], [LoginName], [UserName],
[UserType], [MobileNo], [Email],
[IsLogin], [IpAddress]
FROM
UserMaster
WHERE
IsActive = 1 ' + @Condition
print @query
EXEC sp_executesql @Query
How to pass "like" condition from C# ?