0

I am using SQL server time data type, I have made an sp which returns records from that table, But its throwing exception

'Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible''

I have checked the InnerException and its saying

 'Input String was not in correct format'

When I run my query on SQL server its running fine below is the structure of my table

Id bigint
Name varchar(100)
timefrom time(0)
timeto time(0)

below is my sp

  SELECT * FROM Table1 where condition

I am using NHibernate for data access

public System.Collections.IList GetData(long id)
        {
            string connectionStr = ConfigurationManager.ConnectionStrings["FNHConnection"].ConnectionString;
            IDbConnection conn;
            conn = new SqlConnection(connectionStr);
            conn.Open();
            ISessionFactory sessionFactor = HibernateTemplate.SessionFactory;
            ISession session = sessionFactor.OpenSession(conn);

            var result = session.CreateSQLQuery("exec dbo.gen_GetData ?")
                .SetParameter(0, id)
            .List();

            return result;
        }

its throwing exception on

var result = session.CreateSQLQuery("exec dbo.gen_GetData ?") .SetParameter(0, id) .List();

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Syed Salman Raza Zaidi
  • 2,172
  • 9
  • 42
  • 87

1 Answers1

0

Try to find the solution from the below link:http://msdn.microsoft.com/en-us/library/bb675168.aspx One more link, that can be useful:http://blogs.msdn.com/b/usisvde/archive/2007/11/14/time-for-ado-net.aspx

Amit
  • 15,217
  • 8
  • 46
  • 68