C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




search


Posted Date: 04 Sep 2008      Total Responses: 4

Posted By: prasanthkumar       Member Level: Gold     Points: 1



how to search

when passing from front end textbox (chennai,madrass,kochi)

for location in sql table





Responses

Author: mythili d    04 Sep 2008Member Level: SilverRating:     Points: 2

I do not understand it correctly are you saying that all the three state names are in one text box and they are seperated by commas

Please try this example
declare @sql nvarchar(1000)
declare @loc varchar(100)
set @loc=('chennai,madrass,kochi')
set @sql=('select *from tblItem where location=''' +@loc+'''')
print @sql
exec @sql
Hope this helps.



Author: Geetha    05 Sep 2008Member Level: GoldRating:     Points: 3

public DataTable GetKeywordList(strDBConn)
{
SqlConnection sqlCon = new SqlConnection(strDBConn);
SqlCommand sqlCmd = new SqlCommand();
DataTable dtKeyword = new DataTable();
try
{
sqlCmd.Connection = sqlCon;
sqlCmd.CommandText = "Select * from Citylist where city = '" + txtCity.Text +"'";
sqlCon.Open();
SqlDataAdapter daFile = new SqlDataAdapter();
daFile.SelectCommand = sqlCmd;
daFile.Fill(dtKeyword);
return dtKeyword;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (sqlCon.State == ConnectionState.Open)
sqlCon.Close();
}
}



Author: Lakhan Pal    05 Sep 2008Member Level: GoldRating:     Points: 3

Write Query Like This:
DECLARE @SQLQUERY VARCHAR(200)
SET @SQLQUERY='Select * from Citylist where city IN ('+TextBoxValue+')
EXEC (@SQLQUERY)



Author: http://dotnetvj.blogspot.com    05 Sep 2008Member Level: DiamondRating:     Points: 6

Hi,
User is going to enter 3 cities in one single text box or you have combox box in UI which you can use to select multiple cities?

The finaly query should be if it is single text box.


SELECT * FROM STATES WHERE
(
CITY_NAME LIKE '%MADRAS%'
OR
CITY_NAME LIKE '%HYD%'
OR
CITY_NAME LIKE '%BOM%'
)


If it is List Combobox then


SELECT * FROM STATES WHERE city_name in ('X','Y','Z')


Thanks -- Vj
http://dotnetvj.blogspot.com

Thanks -- Vj

http://dotnetvj.blogspot.com



Post Reply
You must Sign In to post a response.
Next : sql query
Previous : What is sqlinjection?
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use