将日期插入数据库 [英] inserting dates into database

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

问题描述

如何在数据库中的表的单个列中存储3个不同的日期?请帮助我

How to store 3 different dates in single column of a table in a database? pls help me

推荐答案

连接 [ ^ ]多个日期(字符串中) )成单个字符串(用逗号分隔它们),例如,

Concatenate[^] multiple dates(in string) into single string (separate them using comma) like,
string date1 = "1-1-2001";
string date2 = "2-2-2002";
string date3 = "3-3-2003";

string newDate = date1 + ", " + date2 + ", " + date3;

string query = "INSERT INTO TABLE_NAME (COLUMN_NAME) VALUES(newDate)";
// and rest of the stuff...





-KR



-KR


首先你必须将该字段声明为varchar / varchar2。所以它可以占用长字符串。

现在连接日期值,然后将这个连接的值存储在数据库中。
firstly you have to declare the field as varchar / varchar2. so that it can take up the long string.
now concate the date values and then store this concatenated value in the database.


如果您保存数据,就像它打破了第一个CODDS NF规则,即你将存储多个值,这绝不是一件好事。检查:



http://en.wikipedia.org/wiki / Database_normalization [ ^ ]



分解日期可能是Date1,Date2,Date3,因为您已经确定有3个日期。然后像往常一样添加它们:



http: //www.entityframeworktutorial.net/EntityFramework4.3/Introduction.aspx [ ^ ]
If you save your data like that, it breaks the first CODDS NF Rule, that is you will be storing multiple values which is never a good thing. Check this:

http://en.wikipedia.org/wiki/Database_normalization[^]

Decompose the dates maybe like Date1, Date2, Date3, since you are already sure there are 3 date. Then add them like usual like this:

http://www.entityframeworktutorial.net/EntityFramework4.3/Introduction.aspx[^]


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

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