Click here to Skip to main content
15,867,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Here you go:

SQL
/* 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.:
C#
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.:
C#
// 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
 
Share this answer
 
v3
Comments
Bhaskar Dhone 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...??
Joezer BH 4-Feb-13 1:05am    
I've updated the solution to show examples of using SQL in C# code,

Good luck,
Edo
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.
 
Share this answer
 
v2

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