nullable

'ToString()' takes 1 arguments when DateTime?(Nullable) type I uses [duplicate]

对着背影说爱祢 提交于 2019-12-12 01:45:31
问题 This question already has answers here : No overload for method 'ToString" takes 1 arguments when casting date (3 answers) Closed 3 years ago . DateTime? NullableWhen I use DateTime? as Nullable type "ToString("dd MMMMyyyy " + "(HH:mm tt)")" error appears. 回答1: You must use something like this. I've added null check as suggested by Colin if(dateVariable.HasValue) string dateString = dateVariable.Value.ToString("dd MMMMyyyy " + "(HH:mm tt)"); Nullable<T> is a generc and it wraps object. You

trouble with changing default behavior for nullable column get in dataset

我的未来我决定 提交于 2019-12-11 23:14:53
问题 default column get for a dataRow in .designer.cs is like public partial class Fi_securityRow : global::System.Data.DataRow { [global::system.diagnostics.debuggernonusercodeattribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")] public override System.DateTime Exp_dt { get { try { return ((global::System.DateTime)(this[this.tableFi_security.Exp_dtColumn])); } catch (global::System.InvalidCastException e) { throw new global:

PHP Script to fix MySQL columns to work with strict-mode

こ雲淡風輕ζ 提交于 2019-12-11 16:04:34
问题 I'm trying to build a script to generate ALTER TABLE queries so that across whole schemas, columns are adjusted to be compatible with MySQL strict-mode.. I want it to be a simple as possible, making the most basic changes possible for NOT/NOT NULL and Default values to ensure strict-mode compatibility, but at the same time minimising the chances of breaking any existing queries, or associated PHP code that depends on the schema definition's workings. Any tips / things I've missed out / things

Nullable type with inline if cannot work together?

放肆的年华 提交于 2019-12-11 15:54:09
问题 Given the following code: Dim widthStr As String = Nothing This works - width is assigned Nothing : Dim width As Nullable(Of Double) If widthStr Is Nothing Then width = Nothing Else width = CDbl(widthStr) End If But this does not - width becomes 0.0 (although it seems to be logically identical code): Dim width As Nullable(Of Double) = If(widthStr Is Nothing, Nothing, CDbl(widthStr)) Why? Is there anything I can do to make it work? 回答1: This all comes down to type analysis of expressions.

How to pass null for a parameter in stored procedure - the parameter is uniqueidentifier

☆樱花仙子☆ 提交于 2019-12-11 15:43:07
问题 In C# code I have a variable Guid? name.But,how to initialize this parameter to null,since I cannot assign null for a guid type 回答1: Set the parameter value to DBNull.Value . 回答2: param = New SqlParameter("@GUID_ID", SqlDbType.UniqueIdentifier, 16) param.Value = DBNull.Value 来源: https://stackoverflow.com/questions/2490514/how-to-pass-null-for-a-parameter-in-stored-procedure-the-parameter-is-uniqueid

.Net - Cast or convert a boxed byte?, short? or int? to int?

江枫思渺然 提交于 2019-12-11 14:01:44
问题 If I have an object reference that references a byte? , short? or int? , is there a way to unconditionally cast or convert that object reference to int? without writing separate code for each case? For example: byte? aByte = 42; // .. or aByte = null object anObject = aByte; //... var anInt = (int?)anObject //As expected, doesn't work 回答1: I'd use Convert.ToInt32(object): object o = ...; // Boxing... int? x = o == null ? (int?) null : Convert.ToInt32(o); Note that when you box an int? , short

Why Nullable<​DateTime> can be assigned to a paramter which only can be implict converted from DateTime?

[亡魂溺海] 提交于 2019-12-11 11:06:08
问题 There is no implicit conversion from Nullable<​DateTime> to DynamoDB​Entry. But I have code like this. It works well. class DocumentData { private readonly Document doc; protected void SetValue(string key, DateTime? dateTime) { DateTime? old = GetDateTime(key); if (old != dateTime) doc[key] = dateTime; } } In fact, I tested some other code. I think it's nothing to do with DynamoDB. class TestDateTIme { public static void Test() { DateTime? a = DateTime.UtcNow; Convert(a); } public static void

Implicit Interface casts of Nullables

匆匆过客 提交于 2019-12-11 10:22:28
问题 With VB's Option Strict On , why does a Nullable(Of T) not require an explicit cast to an interface of T when it does require one to T ? I.e. Dim x As Integer? = 5 Dim y As Integer Dim z As IComparable y = x ' Fails to compile with error ' "Option Strict On disallows implicit conversions from 'Integer?' to 'Integer'." z = x ' Succeeds EDIT: As (sort of) shown by @SSS, part of the answer is that Nullable values are, well, nullable, and can be Nothing , which is fine for a reference like an

DateTime comparison in ObjectQuery.Where

夙愿已清 提交于 2019-12-11 07:58:14
问题 I'm using Entity Framework, and I have a COMMENT entity. A COMMENT has a DATEMODIFIED property, which is a Nullable Date. I'm trying to build a query that will filter COMMENTs by date, so I create a startDate object, and do the following: Dim q As ObjectQuery(Of COMMENT) = _ (From c In model.COMMENT Select c) If startDate.HasValue Then q = q.Where(Function(c) startDate.Value <= c.DATEMODIFIED) End If The problem is that q.toList() is not returning any comments, even though I think it should.

How to check if a property of an Entity Framework type is Nullable

帅比萌擦擦* 提交于 2019-12-11 06:38:00
问题 I have a EntityDataModel generated from my database. One of the Entity models has two properties that are both string types. One is Nullable=True and the other Nullable=False How do I check the value of the Nullable property during runtime ? 回答1: If your properties are decorated with attributes like [Required] or [StringLength] with a property MinimumLength set to a value greater then 0, you could use that property's GetType() method. This method will return an object of type Type and it has