Click here to Skip to main content
15,888,095 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a database like Design,Website,etc and if i search a data like word W then it shows Website in my gridview so how can i write this query in storeprocedure or c# coding...?
Posted
Comments
Sadique KT 15-Jun-13 6:29am    
A lot of methods available...
select * from TABLENAME where FIELDNAME like 'W%'
pass w as parameter...to the Stored Procedure
OR
You can Use DeExpress Grid , ANd Enable AutoFilter Row in it.

Use wildcard search

SQL
CREATE PROC [dbo].[StoredProcedureName]
(
@Parametername nvarchar(50)
)
AS
 SELECT ColumnName FROM TableName
   WHERE ColumnName LIKE  '%' + @Parametername 


'%' before you criateria mean anything that starts with your criteria, at the end meant end with. Before and after, will bring results containing your given value...
 
Share this answer
 
v2
Comments
kansara darshit 15-Jun-13 6:59am    
It does not work but thank you
A lot of methods available...
select * from TABLENAME where FIELDNAME like 'W%'
pass w as parameter...to the Stored Procedure
OR
You can Use DeExpress Grid , ANd Enable AutoFilter Row in it.
 
Share this answer
 
v3
Comments
kansara darshit 15-Jun-13 7:02am    
I have not only w search i have a different word for search so how can i do that?
Sadique KT 17-Jun-13 2:38am    
You can use the same SP given by Mr. Boipelo --> SELECT ColumnName FROM TableName WHERE ColumnName LIKE @Parametername + '%'
You can pass any word/words via @Parametername to the SP...
1. Create above Sp,
2. Call it from ur solution by passing parameter
3. Read the result returned by sp
4. Add/ populate it to your grid..
C#
string strsql = "SELECT Tags from Table_Name WHERE Name LIKE @p";
SqlCommand cd1 = new SqlCommand(strsql , con);
cd1.Parameters.Add("@p", SqlDbType.NVarChar).Value = p + "%";
SqlDataReader rdr = cd1.ExecuteReader() ;




After that u have to Read the Reader i.e here u have to read the reader using While loop.
while(rdr.Read(){} do the business logic what u want to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900