Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
if data is stored in database say of employee. having column of experience and technology.
 
If i want to search employee by both criteria ....say 1 year experience and java technology....say 2 year experience and .net technology...This is possible , but how to search 1 year experience and any technology...using c#, asp.net...
 

Plz help me out...Thank You !!!
Posted 3-Feb-13 3:25am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here you go:
 
/* 1 year experience and 2 year Java Experience */
SELECT * FROM TblEmployee WHERE experience=1 AND javaExp=2
 
/* 1 year experience and any Java Experience */
SELECT * FROM TblEmployee WHERE experience=1
 
/* 1 year experience in any technology */
SELECT * FROM TblEmployee WHERE Tech1Exp=1 OR Tech2Exp=1 OR Tech3Exp=1
 
You can of course use the SQL from C#, e.g.:
string expValueinCSharp = "2"; // Here you can enter your parameter
string SQL = "SELECT * FROM TblEmployee WHERE experience=" + expValueinCSharp;
 
and using the SQL in C# to get data from the server, e.g.:
 
// Connection String definition:
string sampleConString = @"Server=(local)\sqlexpress;Integrated Security=True;Database=DB";
 
//Connect to the database for Collections Table
SqlConnection Conn = new SqlConnection(sampleConString);
 
//Create DataAdapter Object and use your SQL string
SqlDataAdapter thisAdapter = new SqlDataAdapter(SQL, Conn);
 
//Create DataSet to contain related data tables, rows, and columns
DataSet ds = new DataSet();
 
//Fill DataSet using query defined previously for DataAdapter
thisAdapter.Fill(thisDataSet, "Collection");
foreach (DataRow Row in ds.Tables["MyTable"].Rows)
{
    // do stuff with each 'Row'
}
 
//Close Connection
Conn.Close();
 
NOTE: this is a simplified example, you can methods to improve the above code, like SQL parameters in order to avoid SQL Injection, and you can use LINQ which is pretty cool.
 
Cheers,
Edo
  Permalink  
v3
Comments
Bhaskar Dhone at 3-Feb-13 9:42am
   
Thanks Edo, but I want it in c#, and the search will be dynamic...the value will be given to query by control...say we are searching with two Drop Down Control...one having experience and other having technology...Technology DDL contain All, .NET, C#,etc...??
Edo Tzumer at 4-Feb-13 1:05am
   
I've updated the solution to show examples of using SQL in C# code,
 
Good luck,
Edo
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

CREATE PROCEDURE SearchResult
declare @Experience int=-1,
declare @experiencetech varchar(200)='all'
as
BEGIN
 
select * from TblEmployee
where (experience=@Experience or @Experience=-1)
and (TechExperience like '%'+@experiencetech+'%' or @experiencetech='all')
 
END
 
hope above code resembles your problem
 
from dropdown list pass experience as int in @Experience and Technologyddl text as @experiencetech
 
if want to search all, pass -1 ,'all' as parameter value.
  Permalink  
v2

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

  Print Answers RSS
0 Maciej Los 404
1 OriginalGriff 369
2 Sergey Alexandrovich Kryukov 158
3 CPallini 145
4 Hard_Rockz 85
0 OriginalGriff 5,634
1 Sergey Alexandrovich Kryukov 4,763
2 Peter Leow 2,954
3 Maciej Los 2,614
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid