C# ADO.NET: nulls and DbNull — is there more efficient syntax?

后端 未结 6 2065
时光取名叫无心
时光取名叫无心 2020-12-14 00:03

I\'ve got a DateTime? that I\'m trying to insert into a field using a DbParameter. I\'m creating the parameter like so:

DbParameter         


        
6条回答
  •  遥遥无期
    2020-12-14 00:45

    Ah ha! I found an even more efficient solution than @Trebz's!

    datePrm.Value = nullableDate ?? (object)DBNull.Value;
    

提交回复
热议问题