Reputation: 1020
Here is my table structure I am attaching the Image of table with records
When I am trying to getting the data from this table and want to display it on a page then i am getting error like this
invalidCastException: Unable to cast object of type 'System.TimeSpan' to type 'System.Nullable`1[System.DateTime]'. ThrowDataException InvalidOperationException: Error parsing column 5 (EventTime=11:30:00 - Object)
I am using this command select * from events
in stored procedure to get the all records from this table.
Data type of EventTime
column is time and when I am creating the property of this column on c# then the datatype is datetime
hiow can i resolve this problem?
here is the stored procedure code to understand better
USE [RG_DEC12]
GO
/****** Object: StoredProcedure [dbo].[GetAllBlogs] Script Date: 12/20/2016 12:01:57 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Gaurav Sharma>
-- Create date: <20/12/2016>
-- Description: <Description,,>
-- =============================================
alter PROCEDURE [dbo].[GetEvents]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
select * from Events
END
Upvotes: 1
Views: 3222
Reputation: 1020
i got the answer we need to cast eventtime column like this
CONVERT(char(10), eventtime, 108) as EventTime
Upvotes: 0