Robert
Robert

Reputation: 33

Stored Procedure results different in SQL and C#

I am calling a stored procedure in my code and the results are being loaded into a DataTable, here is a column from the Datatable.

Code Results Column

However, the time portion of the date is not supposed to be there. In the stored procedure, I am doing this: "Cast(loan.OpenedDate as date) as OpenedDate". In SQL if I execute this stored procedure, it displays correctly as shown here.

SQL Results Column

Why would the results differ if the procedure is the same?

Upvotes: 0

Views: 182

Answers (2)

Mihir Dave
Mihir Dave

Reputation: 4014

That's Because in Code it has DataType of DateTime because C# Doesn't have Date DataType

So what you do is Use DateTime.ToShortDateString Method

E.g

DateTime dateToDisplay = new DateTime(2009, 6, 1, 8, 42, 50);
dateToDisplay.ToShortDateString()

Upvotes: 1

UmmmActually
UmmmActually

Reputation: 217

There is no Date type in C#, only DateTime, so your SQL Date result is being converted to a DateTime.

Upvotes: 2

Related Questions