Hi Nedash,
please use the following snippet, as you need to update your SP a bit and then your code would be run as expected.
-- =============================================
-- Author: Rk_Hirpara
-- Create date: 20/05/2013
-- Description: <Description,,>
-- =============================================
alter PROCEDURE SearchTermP
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @SearchTerm TABLE
(
Id INT,
Name VARCHAR(100)
)
-- THIS TABLE WOULD BE REPLACED WITH YOUR RESPECTIVE TABLE
DECLARE @House_info TABLE
(
Id INT,
[DESCRIPTION] VARCHAR(100)
)
-- THIS TABLE WOULD BE REPLACED WITH YOUR RESPECTIVE TABLE
INSERT INTO @SearchTerm VALUES (1,'India')
,(2,'Paris')
,(3,'Itally')
,(4,'Economy')
,(5,'Country')
INSERT INTO @House_info VALUES(1,'I love my India')
,(2,'Here is paris and I love itally and I love parishilton')
SELECT DISTINCT houseInfo.ID,Name INTO #TBL FROM @House_info houseInfo,@SearchTerm WHERE [DESCRIPTION] LIKE '%' + Name + '%'
SELECT houseInfo.Id
,houseInfo.[DESCRIPTION]
,searchResult.Name
FROM @House_info houseInfo
INNER JOIN #TBL searchResult
ON houseInfo.Id = searchResult.Id
DROP TABLE #TBL
END
GO
.CS
;
protected void HouseP_Click(object sender, EventArgs e)
{
string openingTag = "<span style='background-color:Yellow'><b>";
string closingTag = "</b></span>";
DataTable dt = Fill();
foreach (DataRow dr in dt.Rows)
{
dr[1] = Regex.Replace(dr[1].ToString() + " ", " " + dr[2].ToString() + " ", " " + openingTag + dr[2].ToString() + closingTag + " ", RegexOptions.IgnoreCase);
}
DataList1.DataSource = dt;
DataList1.DataBind();
}
private DataTable Fill()
{
SqlDataAdapter ADP = new SqlDataAdapter();
ADP.SelectCommand = new SqlCommand();
ADP.SelectCommand.Connection = _cn;
ADP.SelectCommand.CommandText = "SearchTermP";
ADP.SelectCommand.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
_cn.Open();
ADP.Fill(dt);
_cn.Close();
return dt;
}
I have provided all the resources which is required to fullfill your task. So please implement.
Thanks and Regards,
Rk_Hirpara.