【问题标题】:How to use SQL server time data type? [duplicate]如何使用 SQL Server 时间数据类型? [复制]
【发布时间】:2013-03-13 07:10:45
【问题描述】:

我正在使用 SQL 服务器时间数据类型,我制作了一个从该表返回记录的 sp, 但它抛出异常

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

我已经检查了 InnerException 及其说法

 'Input String was not in correct format'

当我在 SQL 服务器上运行查询时,它运行良好 下面是我的表结构

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

下面是我的sp

  SELECT * FROM Table1 where condition

我正在使用 NHibernate 进行数据访问

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;
        }

它在

上抛出异常

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

【问题讨论】:

    标签: c# sql-server


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      相关资源
      最近更新 更多