Searching Query in sql database

Posted by Rock_Monu under ASP.NET on 3/6/2013 | Points: 10 | Views : 6443 | Status : [Member] | Replies : 4
how to search data from database like organisation wise ,dept wise,division wise etc ..
?means i want filteration query by category wise?




Responses

Posted by: Karthikreddy on: 3/7/2013 [Member] Starter | Points: 25

Up
0
Down
Question is no clear !!. i think you want search data from database by category wise

SELECT * FROM Employees WHERE (Title LIKE '::dept ::') or

SELECT * FROM Employees WHERE (Title Like '% dept %')

k@rth!k
karthikreddy08a50@gmail.com

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 3/7/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Rock_Monu,

Can you elaborate the requirement

sample

select * from table where CategoryName = "Name of Category"

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sailajareddy on: 3/8/2013 [Member] Starter | Points: 25

Up
0
Down
SELECT * FROM tablename WHERE Category LIKE '%Dept%' -- To filter all the rows containing department in the category

SELECT * FROM tablename WHERE Category LIKE '%Organisation%' -- To filter all the rows containing Organisation in the category

SELECT * FROM tablename WHERE Category LIKE '%Division%' -- To filter all the rows containing Division in the category

SailajaReddy

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhi on: 3/10/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

You need to filter the values according to the selection of values right.
If i am right, See this following example.
I have done like this, i used to concatenate the query values according to the selection.
The values will get filtered and it will be displayed on the gridview.
For example:
If you have dropdownlist for organisation,department,division,etc., you need to filter the values according to these selection.

Design page:
<body>

<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlOrganisation" runat="server"
onselectedindexchanged="ddlOrganisation_SelectedIndexChanged">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Organisation</asp:ListItem>
<asp:ListItem>Org</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlDepartment" runat="server"
onselectedindexchanged="ddlDepartment_SelectedIndexChanged">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Software</asp:ListItem>
<asp:ListItem>Networking</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlLocation" runat="server"
onselectedindexchanged="ddlLocation_SelectedIndexChanged">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Hydrebad</asp:ListItem>
</asp:DropDownList>
</div>

</form>

</body>

.CS Page:
public partial class Default2 : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)
{
PopulateValues();
}
protected void ddlOrganisation_SelectedIndexChanged(object sender, EventArgs e)
{
PopulateValues();
}
protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
PopulateValues();
}
protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
PopulateValues();

}
protected void PopulateValues()
{
string Query = "Select * from tablename where empresignedstatus ='No'";
if(ddlDepartment.SelectedItem.Text !="Select")
Query += "and Department='"+ ddlDepartment.SelectedItem.Value+"'";
if(ddlOrganisation.SelectedItem.Text != "Select")
Query += "and Organisation='" + ddlOrganisation.SelectedItem.Value + "'";
if (ddlLocation.SelectedItem.Text != "Select")
Query += "and Location='" + ddlLocation.SelectedItem.Value + "'";

//Here write the SQL Execution coding.


}
}



If you have not selected any values from the dropdownlist, Values will not be filtered ..
If you have chosen any values on any one of the dropdown the values will be filtered according to the selection
Display those values where you need..
Let me know, if you have any queries


Thanks & Regards,
Santhi .V

Rock_Monu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response