c# - 指定的转换在 C# 中无效

标签 c#

我在数据库表中有一个 bigint 类型的列。我希望它检索并将其分配给 C# 中的变量,如下面的示例所示。

示例:

obj.Total1 = (Int32)reader["Slno"] != null ? (Int32)reader["Slno"] : 0;
obj.Total2 = (Int32)reader["Rlno"] != null ? (Int32)reader["Rlno"] : 0;

注意:这里的SlnoRlno在数据库表中都是bigint类型。

错误:以下是错误信息。

Specified cast is not valid.

最佳答案

SQL 的 BigInt 映射到 C# 中的 long,而不是 int

关于c# - 指定的转换在 C# 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24885917/

相关文章:

c# - 参数无效。 - 只发生在 Gif 上

C#,比较两种不同类型的列表

c# - C# 中没有智能感知

c# - 如何在 3D 透视图中对 windows 8 UIElements 进行 Z 索引(Z 排序)?

c# - OpenRasta 通过 JsonDataContractCodec 返回列表

c# - Xamarin App 中的认知服务异常

c# - C# 新手并尝试使用全局变量

c# - Owin Authentication.SignIn 不工作

c# - OWIN 启动不工作

c# - WPF:MVVM 中的命令和 ViewModel 关系