C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

like conditin with or and and urgent


Posted Date: 03 Dec 2008      Posted By: gompra      Member Level: Silver     Points: 1   Responses: 2



hi,

i have code like this below

if (txtCode.Text.Trim() != "")
{
//this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition);
this.SearchCondition += "Code LIKE '" + txtCode.Text.Trim() +"%'";
}
if (txtName.Text.Trim() != "")
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition);
this.SearchCondition += "Name LIKE '" + txtName.Text.Trim() + "%'";
}
if (ddlJob.SelectedIndex > 0)
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition);
this.SearchCondition += "Job = '" + ddlJob.SelectedItem.Text + "'";
}
if (ddlStatus.SelectedIndex > 0)
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition);
this.SearchCondition += "Status = '" + ddlStatus.SelectedItem.Text + "'";
}


for this above coding i want in search condition with this format

(code like 'a%' or name like 'b%')and c='some'

where i will add the brackets
how to add correctly
this is urgent tell me






Responses

Author: Roopesh Babu Valluru    03 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

Hi...

First add all the conditions that has AND and then OR and ur req becomes like :

c='some' and (code like 'a%' or name like 'b%')

now...

if (txtCode.Text.Trim() != "")
{
//this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition);
this.SearchCondition += "Code LIKE '" + txtCode.Text.Trim() +"%' and ";
}

if (txtName.Text.Trim() != "" || ddlJob.SelectedIndex > 0)
{
this.SearchCondition += "(";
}

if (txtName.Text.Trim() != "")
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition);
this.SearchCondition += "Name LIKE '" + txtName.Text.Trim() + "%' or ";
}
if (ddlJob.SelectedIndex > 0)
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition+" or");
this.SearchCondition += "Job = '" + ddlJob.SelectedItem.Text + "'";
}
if (txtName.Text.Trim() != "" || ddlJob.SelectedIndex > 0)
{
this.SearchCondition += ")";
}

Hope the above will work..

All Teh Best...



Author: Preet    03 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

hi,

i have code like this below

if (txtCode.Text.Trim() != "")
{
//this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition);
this.SearchCondition += "(Code LIKE '" + txtCode.Text.Trim() +"%'";
}
if (txtName.Text.Trim() != "")
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition);
this.SearchCondition += "Name LIKE '" + txtName.Text.Trim() + "%')";
}
else
this.SearchCondition += ")"
if (ddlJob.SelectedIndex > 0)
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition);
this.SearchCondition += "Job = '" + ddlJob.SelectedItem.Text + "'";
}
if (ddlStatus.SelectedIndex > 0)
{
this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition);
this.SearchCondition += "Status = '" + ddlStatus.SelectedItem.Text + "'";
}



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Image size
Previous : Asp.net Certification
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use