如何在详细信息上插入null日期



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

其他信息:SQLDATETIME溢出。必须是1/1/1753 12:00:00 AM到12/31/9999 11:59:59 PM。

<div>        
    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="IDREFUNDSELESAI" DataSourceID="RefundSelesaiObjectDataSource">
        <Fields>                               
            <asp:BoundField DataField="TANGGAL" HeaderText="TANGGAL" SortExpression="TANGGAL" DataFormatString="{0:d}" />

<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" /> 

bll.cs

[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;

感谢您的帮助

DateTime是一个值类型。价值类型不能为空。好吧,除非您使用无效类型

尝试

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

public bool AddRefundSelesai(DateTime? TANGGAL)

相关内容

  • 没有找到相关文章

最新更新