Click here to Skip to main content
12,504,462 members (55,853 online)
Rate this:
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ASP.NET , +
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#,

Plz help me out...Thank You !!!
Posted 3-Feb-13 3:25am
Rate this: bad
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

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.

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 having experience and other having technology...Technology DDL contain All, .NET, C#,etc...??
Edo Tzumer 4-Feb-13 1:05am
I've updated the solution to show examples of using SQL in C# code,

Good luck,
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

declare @Experience int=-1,
declare @experiencetech varchar(200)='all'

select * from TblEmployee
where (experience=@Experience or @Experience=-1)
and (TechExperience like '%'+@experiencetech+'%' or @experiencetech='all')


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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100