nullable

Nullable Int Column in DataSet

烂漫一生 提交于 2020-01-21 06:49:47
问题 I'm working with .NET strongly-typed datasets and have a table with a nullable int column (and a nullable DateTime column as well). Apparently there is a bug with the dataset designer that prevents having nullable columns on these data types. The designer only allows "throw exception" as the default behavior for null values. Unfortunately, when using a nullable data type in the database, a null value IS a legitimate value but results in a thrown exception when attempting to retrieve this

Workaround for “null primitives” in JDBC PreparedStatement? [duplicate]

霸气de小男生 提交于 2020-01-20 05:59:45
问题 This question already has answers here : Inserting null to an Integer column using JDBC (2 answers) Closed 2 years ago . When using raw JDBC, you can parameterize a PreparedStatement like so: PreparedStatement statement = connection.prepareStatement(someSQLString); String someString = getSomeString(); Integer int = getSomeInteger(); statement.setString(1, someString); statement.setLong(2, 5L); statement.setInt(3, int); ... Here, if someString is null , that's fine - strings are nullable. But

Workaround for “null primitives” in JDBC PreparedStatement? [duplicate]

假装没事ソ 提交于 2020-01-20 05:56:45
问题 This question already has answers here : Inserting null to an Integer column using JDBC (2 answers) Closed 2 years ago . When using raw JDBC, you can parameterize a PreparedStatement like so: PreparedStatement statement = connection.prepareStatement(someSQLString); String someString = getSomeString(); Integer int = getSomeInteger(); statement.setString(1, someString); statement.setLong(2, 5L); statement.setInt(3, int); ... Here, if someString is null , that's fine - strings are nullable. But

Workaround for “null primitives” in JDBC PreparedStatement? [duplicate]

假装没事ソ 提交于 2020-01-20 05:56:10
问题 This question already has answers here : Inserting null to an Integer column using JDBC (2 answers) Closed 2 years ago . When using raw JDBC, you can parameterize a PreparedStatement like so: PreparedStatement statement = connection.prepareStatement(someSQLString); String someString = getSomeString(); Integer int = getSomeInteger(); statement.setString(1, someString); statement.setLong(2, 5L); statement.setInt(3, int); ... Here, if someString is null , that's fine - strings are nullable. But

Nullable reference types: How to specify “T?” type without constraining to class or struct

夙愿已清 提交于 2020-01-19 09:27:38
问题 I want to create a generic class that has a member of type T . T may be a class, a nullable class, a struct, or a nullable struct. So basically anything. This is a simplified example that shows my problem: #nullable enable class Box<T> { public T Value { get; } public Box(T value) { Value = value; } public static Box<T> CreateDefault() => new Box<T>(default(T)); } Due to using the new #nullable enable feature I get the following warning: Program.cs(11,23): warning CS8653: A default expression

Nullable reference types: How to specify “T?” type without constraining to class or struct

十年热恋 提交于 2020-01-19 09:20:55
问题 I want to create a generic class that has a member of type T . T may be a class, a nullable class, a struct, or a nullable struct. So basically anything. This is a simplified example that shows my problem: #nullable enable class Box<T> { public T Value { get; } public Box(T value) { Value = value; } public static Box<T> CreateDefault() => new Box<T>(default(T)); } Due to using the new #nullable enable feature I get the following warning: Program.cs(11,23): warning CS8653: A default expression

Are nullable types reference types?

邮差的信 提交于 2020-01-18 19:35:49
问题 When I declare an int as nullable int? i=null; Does i here become a reference type? 回答1: No, a nullable is a struct. What is happening is that the nullable struct has two values: The value of the data type ( int for int? , DateTime for DateTime? , etc.). A boolean value which tells if the data type value has been set. ( HasValue is the property.) When you set the value of the data type, the struct changes HasValue to true. Nullable types (C# Programming Guide) 回答2: From Nullable Types (C#

Are nullable types reference types?

好久不见. 提交于 2020-01-18 19:35:46
问题 When I declare an int as nullable int? i=null; Does i here become a reference type? 回答1: No, a nullable is a struct. What is happening is that the nullable struct has two values: The value of the data type ( int for int? , DateTime for DateTime? , etc.). A boolean value which tells if the data type value has been set. ( HasValue is the property.) When you set the value of the data type, the struct changes HasValue to true. Nullable types (C# Programming Guide) 回答2: From Nullable Types (C#

System.Nullable<T> What is the value of null * int value?

冷暖自知 提交于 2020-01-14 12:41:32
问题 Consider the following statements: int? v1 = null; int? v2 = 5 * v1; What is the value of v2 ? ( null or empty string?) How can I prevent the compiler to mark it as invalid operation? Do I need to follow custom exception handling? 回答1: It's null . C# Language Specification 3.0 (Section §7.2.7: Lifted operators) For the binary operators + - * / % & | ^ << >> : a lifted form of an operator exists if the operand and result types are all non-nullable value types. The lifted form is constructed by

System.Nullable<T> What is the value of null * int value?

送分小仙女□ 提交于 2020-01-14 12:40:58
问题 Consider the following statements: int? v1 = null; int? v2 = 5 * v1; What is the value of v2 ? ( null or empty string?) How can I prevent the compiler to mark it as invalid operation? Do I need to follow custom exception handling? 回答1: It's null . C# Language Specification 3.0 (Section §7.2.7: Lifted operators) For the binary operators + - * / % & | ^ << >> : a lifted form of an operator exists if the operand and result types are all non-nullable value types. The lifted form is constructed by