I have one class named e.g abc.cs
. I am using custom function for searching criteria like this:
public System.Data.DataTable myFunction(string SearchText, string ColumnName, string
SearchCriteria)
{
// ColumnName is the name of the column in db table as shown below in
// query e.g a , b , c , d, e
try
{
string strQuery = "SELECT a,b,c,d,e FROM myTable ";
SearchText = SearchText.Trim().Replace("[", "[[]");
SearchText = SearchText.Trim().Replace("'", "''");
SearchText = SearchText.Trim().Replace("%", "[%]");
SearchText = SearchText.Trim().Replace("_", "[_]");
if (SearchText != "")
{
strQuery += " where " + ColumnName + " LIKE ";
if (SearchCriteria == "x")
{
strQuery += "'" + SearchText + "%'";
}
else if (SearchCriteria == "y")
{
strQuery += "'%" + SearchText + "'";
}
else if (SearchCriteria == "z")
{
strQuery += "'%" + SearchText + "%'";
}
else
{
strQuery += "'" + SearchText + "'";
}
}
strQuery += "ORDER BY b";
}
catch (Exception E)
{
}
}
The store procedue which I have tried so far:
USE [dbName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[abc]
@SearchText nvarchar(100)
AS
BEGIN
SELECT a,b,c,d,e FROM myTable ;
-- what should be the criteria here.
END
GO
I am stuck at point how to use searchText
in conditions in store procedure, and than what is the way to use searchText
in myFunction
.