Searching records between two dates is very simple. In here, we will see how we can perform this using a stored procedure with Entity Framework in ASP.NET MVC.
Step 1. Open SQL Server Management Studio and create a table named 'Employee'.
CREATE TABLE [dbo].[Employee] (
[Id] [int] NOT NULL,
NULL,
NULL,
[JoiningDate] [date] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
) WITH (
PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON
) ON [PRIMARY]
) ON [PRIMARY];
GO
SET ANSI_PADDING OFF;
GO
Step 2. Create a stored procedure to find the data between two dates.
CREATE PROC [dbo].[Usp_Empsearch]
@Fromdate DATETIME,
@Todate DATETIME
AS
BEGIN
SELECT *
FROM Employee
WHERE JoiningDate BETWEEN @Fromdate AND @Todate;
END
Step 3. Open Visual Studio and create a new project.

Change the name to SearchRecord and select MVC as its template.
Step 4. Right-click the Models folder from Solution Explorer and go to Add >> New Item >> data.

Select EF designer from the database and click the "Next" button.

Add the connection properties and select the database name on the next page followed by a click on OK.
Check the table and stored procedure checkboxes. The internal options will be selected by default. Now, click the "Finish" button.

Our data model is created now.
Step 5. Right-click on Edmx, add New >Function Import >enter the name and import function and table. Now, click on the "Get column information" option.

Step 6. Now, right-click on the Controllers folder and add a new MVC controller named 'SearchController'.
Add the following code to that.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SearchRecord.Controllers
{
public class SearchController : Controller
{
// GET: Search
public ActionResult Index()
{
Test1Entities1 DB = new Test1Entities1();
return View(DB.Employees.ToList());
}
[HttpPost]
public ActionResult Index(DateTime From, DateTime To)
{
Test1Entities1 DB = new Test1Entities1();
return View(DB.SearchData(From, To));
}
}
}


Msrao RaoPosted Jul 25, 2019, 2:51 AM
How to write code in c sharp using text box value adding to deposit date as datepicker1 and answer value appear in date picker 2