我使用存储过程来获取分页列表,这是我的方法:
using(SqlConnection conn = new SqlConnection(_connectionString)) {
using(SqlCommand cmd = new SqlCommand("[GetPagedSP]", conn)) {
cmd.CommandType = System.Data.CommandType.StoredProcedure;
//Passing Parameters
**Update**
SqlParameter spCreationDate = new SqlParameter("@CreationDate_9", CreationDate);
spCreationDate.IsNullable = true;
cmd.Parameters.Add(spCreationDate);
// ........
//Finished Passing Parameters
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read()) {
//Get Values
}
conn.Close();
}
}
这是我的存储过程命令:
CREATE TABLE #PagingTemp (
[RowId] [bigint] IDENTITY(1,1) NOT NULL,
[RecordId] [bigint]
);
INSERT INTO [#PagingTemp] ([RecordId])
SELECT [CAR].[Id]
FROM [Article] AS [CAR] ;
SELECT [CAR].*
FROM [Collections].[Article] AS [CAR]
INNER JOIN [#PagingTemp] AS [PT] ON [CAR].[Id] = [PT].[RecordId]
WHERE [PT].[RowId] BETWEEN 1 AND 50;
当我在 SQL 中运行查询时,一切都很好,但在 .NET 中,我在这一行有一个例外:
SqlDataReader dr = cmd.ExecuteReader();
例外是:
System.Data.SqlTypes.SqlTypeException 未被用户代码
Message=SqlDateTime 溢出处理。必须介于 1753 年 1 月 1 日上午 12:00:00 和 9999 年 12 月 31 日晚上 11:59:59 之间。
源=系统.数据
更新
在 SQL 中运行 Query 的示例:
太奇怪了,不明白怎么回事?
我没有任何datetime
大于12/31/9999
或小于的值1/1/1753
我在数据库中只有一些具有空值的可空日期时间值。
你怎么看?问题出在哪里?