Nullable GUID

后端 未结 10 2225
北荒
北荒 2020-12-15 04:36

In my database, in one of the table I have a GUID column with allow nulls. I have a method with a Guid? parameter that inserts a new data row in the table. However when I s

10条回答
  •  孤城傲影
    2020-12-15 04:41

    You can use a helper method:

    public static class Ado {
        public static void SetParameterValue( IDataParameter parameter, T? value ) where T : struct {
            if ( null == value ) { parameter.Value = DBNull.Value; }
            else { parameter.Value = value.Value; }
        }
        public static void SetParameterValue( IDataParameter parameter, string value ) {
            if ( null == value ) { parameter.Value = DBNull.Value; }
            else { parameter.Value = value; }
        }
    }
    

提交回复
热议问题