title: How to use SQL server time data type?
body: <p>I am using SQL server time data type, I have made an sp which returns records from that table,
  But its throwing exception </p>
  
  <pre><code>'Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible''
  </code></pre>
  
  <p>I have checked  the InnerException and its saying</p>
  
  <pre><code> 'Input String was not in correct format'
  </code></pre>
  
  <p>When I run my query on SQL server its running fine
  below is the structure of my table</p>
  
  <pre><code>Id bigint
  Name varchar(100)
  timefrom time(0)
  timeto time(0)
  </code></pre>
  
  <p>below is my sp</p>
  
  <pre><code>  SELECT * FROM Table1 where condition
  </code></pre>
  
  <p>I am using NHibernate for data access</p>
  
  <pre><code>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;
          }
  </code></pre>
  
  <p>its throwing exception on </p>
  
  <p>var result = session.CreateSQLQuery("exec dbo.gen_GetData ?")
                  .SetParameter(0, id)
              .List();</p>