Click here to Skip to main content
15,906,624 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

Can anyone help me to create an Search module with four textbox

Module Details :

4 Textbox
1 Search Button.
Table : Employee
Table Fields : ID , Name , Location, Mobile , Salary and Designation.

Functionality :
User can Search the Emplaoyee Details by using the Textbox,1 Text box field to fill is mandatory and he can also enter 2 fields ,3 fields or 4 fields depends on the filtration.


Can anyone help me . in MVC code using SQL Server as Backend DB

What I have tried:

Can anyone help me . in MVC code using SQL Server as Backend DB
Posted
Updated 29-Sep-16 22:54pm

Although ASP.NET MVC implements and makes a good use of Entity framework, for that I would suggest using LINQ queries. Such as,
C#
var people = dbContext.GetPeople();
var person = (from p in people
              where p.Name == requiredName
              select p).ToList();

// Other operations.

If that is not the case and you want to implement your own search, then this article of mine might help you, How to search for related query inside the Database using ASP.NET[^]. That requires an SQL statement to search for the related terms,
C#
// ASP.NET
var requiredName = $"%{query}%";
var sqlStatement = "SELECT * FROM Persons WHERE [Name] LIKE @0";
var result = db.Query(sqlStatement, requiredName);

The ASP.NET way of doing this is a bit different, and this code has SQL Injection prevention method implemented. If you want to use objects in SqlClient namespace, then consider the SqlParameter objects.

System.Data.SqlClient Namespace[^]
LINQ (Language-Integrated Query)[^]
 
Share this answer
 
Comments
Karthik_Mahalingam 30-Sep-16 5:26am    
not an exact answer to the OP's question, but it deserves 5!

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