【问题标题】:how pass the null value using datetime datatype in asp.net and database is mysql?如何在 asp.net 中使用 datetime 数据类型传递空值,而数据库是 mysql?
【发布时间】:2011-08-13 05:21:11
【问题描述】:

我使用的是 asp.net 2.0,数据库是 Mysql 和 我正在使用 datetime 数据类型将 null 值传递给 mysql 表,如下所示 duedate is datetime

if (ddlTerms.SelectedItem.Text.ToString() != "--Select--")
   {
     DateTime createDate = DateTime.Now.AddDays(Convert.ToDouble(ddlTerms.SelectedValue));
     oInvHeader.DueDate = createDate;
   }
   else
   {
    oInvHeader.DueDate =(how to write the code here)
   }

invoiceHeader.cs 代码中

using System;
using System.Data;
using MySql.Data.MySqlClient;
using System.Text;

 private DateTime m_DueDate;

public DateTime DueDate
        {
            get
            {
                return m_DueDate;
            }
            set
            {
                m_DueDate = value;
            }
        }

请帮助我 感谢你 赫曼斯

【问题讨论】:

标签: c# .net asp.net stored-procedures


【解决方案1】:

首先你的DueDate 属性应该是nullable 才能接受空值。

然后你可以像..一样分配空值

oInvHeader.DueDate = null;

这是,我们如何声明nullable 变量

DateTime? DueDate;

【讨论】:

  • 如何将日期时间属性设置为空(我在 asp.net 中询问 db r 字段)
  • 这个 oInvHeader.DueDate 是什么?你在使用任何代码生成工具吗?
  • 在数据访问层上没有,我正在使用 invoiceheader.cs,因此类对象是 oinvHeader,而到期日期是日期时间数据类型
  • 你能给我看那个cs文件吗?您可以编辑您的问题并粘贴该 cs 文件代码。
【解决方案2】:

公共虚拟可空变量名

默认为空

【讨论】:

    【解决方案3】:
    class test
    { 
        public virtual Nullable<Int32> ReagentSupplyCode
         {
            get;
            set;
         }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-05
      • 2018-04-06
      • 1970-01-01
      • 2019-09-03
      • 2021-05-04
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多