如何在detailsview上插入null日期

时间:2017-09-28 08:36:19

标签: c# date null

我在数据库和数据集中设置了date列可能包含空值。但是,当程序运行时,它总是请求填写日期列。错误如下:

  

附加信息:SqlDateTime溢出。必须在1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间。

<asp:ObjectDataSource ID="RefundSelesaiObjectDataSource" runat="server" SelectMethod="GetRefundSelesaiByIdRefund" TypeName="dms_mkph.bll.RefundSelesaiClass" DeleteMethod="DeleteRefundSelesai" InsertMethod="AddRefundSelesai" UpdateMethod="UpdateRefundSelesai"  >           
    <DeleteParameters>
        <asp:Parameter Name="idRefundSelesai" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="TANGGAL" Type="DateTime" /> 
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public bool AddRefundSelesai(DateTime TANGGAL)
    {
        // Create a new ProductRow instance
        RefundDataSet.REFUNDSELESAIDataTable dtRefundSelesai = new RefundDataSet.REFUNDSELESAIDataTable();
        RefundDataSet.REFUNDSELESAIRow rRefundSelesai = dtRefundSelesai.NewREFUNDSELESAIRow();                

        if (TANGGAL == null) rRefundSelesai.SetTANGGALNull(); else rRefundSelesai.TANGGAL = TANGGAL;

bll.cs

{{1}}

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

DateTime是一种值类型。值类型不能为null。除非您使用Nullable类型

尝试

<asp:Parameter Name="TANGGAL" Type="DateTime?" ConvertEmptyStringToNull="True" /> 

public bool AddRefundSelesai(DateTime? TANGGAL)