Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Conditional where clause inline query if parameter is empty

$
0
0

In my application i am writing inline query to retrieve data from data base. not using stored procedure. One of my search functionality i am passing two parameter  Firstname and lastname , If user not passing one of the parameter no  need to include that parameter in query . we achieve ths in procedure using (@EmployeeId IS NULL OR EmployeeID = @EmployeeID) this code. But same  thing how will achieve with c#?

public void search( string firstName, string lastName)

{

string sqlquery=" select * from tablename where FirstName="+firstName and // If lastname not empty then only need to add in query

}


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>