简体   繁体   中英

Get records of specific month or date from datetimepicker value to stored procedure

I want to get all records from a SQL Server database; I am using Entity Framework and C#.

I am using a DateTimePicker value to passed to the stored procedure, and the stored procedure is expecting for datetime object when I pick data from datetime picker it get whole string but I need only date. I tried with datetime object but no success place that value to datetime object dt

Now the problem is that when I try to change format of datetimepicker it convert it to string but I need datetime obj but only with date

 DateTime dt = dateTimePicker1.Value.Date;
 dataGridView1.DataSource = dbobj.sp_Select_Expense_Month(dt).ToList();

How to pass something to stored procedure? Please help me lot of prayers for all commentators

I have tried many solution but the closest was with like query in a stored procedure but it didn't show any results but headers called in gridview and even when I tried that in SQL Server Management Studio it show same thing columns name without any record

ALTER PROCEDURE sp_Select_Expense_Month
    @dt dateTime
AS
BEGIN
    SELECT * 
    FROM Expense 
    WHERE [DateTime] LIKE '@dt%'
END
GO

in database structure its type of date only

You can trim the time from datetime even in sql

SELECT * FROM Expense WHERE [DateTime] = cast(@dt as date)

Make sure you pass valid datetime format

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM