如何将空日期值保存到oracle数据库 [英] how to save a null date value to oracle database

查看:428
本文介绍了如何将空日期值保存到oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static void AddNewStudent(int Stu_id, string Stu_Name, string Class, string Major, Datetime Enddate)
  {
  OracleDatabase db =(OracleDatabase)DatabaseFactory.CreateDatabase("PHTS");
 using (System.Data.Common.DbCommand cmd = db.GetStoredProcCommand("AddNewStudent"))  
           {
  db.AddInParameter(cmd, "I_Stu_id", DbType.Int32, Stu_id);
  db.AddInParameter(cmd, "I_Stu_Name", DbType.String, Stu_Name);
  db.AddInParameter(cmd, "I_Class", DbType.String, Class);
  db.AddInParameter(cmd, "I_Major", DbType.String, Major);
  db.AddInParameter(cmd, "I_Enddate", DbType.Date, Enddate, Enddate == null? DBNull.Value : Enddate);
    db.ExecuteNonQuery(cmd);
            }
  }



用户界面



User Interface

private void Savebutton_Click(object sender, EventArgs e)
{
private void Savebutton_Click(object sender, EventArgs e)
        {
            int student_id = Convert.ToInt32(this.SIDtextBox.Text);
            string stu_name = this.textBox1.Text;
            string class = this.textBox2.Text;
            string major= this.textBox3.Text;
	    Datetime enddate = Datetime.Parse(this.textbox4.text);
 if (this.textbox4.Text == "")
            {
                enddate = null;// DBNull.Value;
            }
            else
            {
                enddate = DateTime.Parse(this.textbox4.Text);
            }

 
PHTS.DataServices.cslMaterial.AddNewStudent(stu_id, stu_name, class, major, enddate);
            MessageBox.Show("Record Saved");

}
}
}




程序




Procedure

Create or replace PRPCEDURE AddNewStudent (
I_STU_ID    Number,    
I_STU_Name  Varchar2,
I_Address  Varchar2,
I_Phone  Varchar2,
I_Enddate   date,
)
As
Begin
Insert into I_Student
(
Student_ID, STU_Name, Address, Phone, Enddate
)
Values
(
I_Student_ID, I_STU_Name, I_Address, I_phone, I_Date , I_Enddate
);



最后,我感谢您的帮助



Finally I got it thanks for helping

推荐答案

尝试:
db.AddInParameter(cmd, "I_Enddate", DbType.Date, Enddate == null ? DBNull.Value : Enddate);


这篇关于如何将空日期值保存到oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆