如何在数据库中插入一行 [英] how to insert a row into database

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

问题描述

嗨...

我有一张桌子叫做Thoughts
在那我有两个领域
日期和想法

现在位于.aspx页面C#代码的前端
有一个文本框和一个提交按钮.
当我在文本框中输入文字时,应该保存
在带有日期的思想表中..
日期应按升序排列.

即如果我今天一次输入数据,那么今天是日期.
如果我输入日期两次是明天明天
如果我输入明天明天后三天的日期..

实际上我想输入一年的想法
365个想法,我想按日期检索该想法.

请帮助我..

hi...

i''ve one table called thoughts
in that i''ve two fields
date and thoughts

now in front end that is in .aspx page C# code
there''s one textbox and one submit button.
when i enter text into textbox it should save
in thought table with the date..
the date should be in increment order..

i.e if i enter the data one time today then today''s date.
if i enter the date two times tommorrows date
if i enter the date three times day after tommorrow''s date..

actually i want to enter the thoughts for one year that is
365 thoughts and i want to retrive the thought by date..

Please help me..

推荐答案

您是说要根据现有行在第二天添加一行.然后该语句可能类似于:
Do you mean that you add a row for the next day based on existing rows. Then the statement could be something like:
insert into Thoughts (TheThought, DisplayDate)
SELECT 'Some thought', COALESCE(MAX(DATEADD(Day, 1, Display)) , GETDATE())FROM Thoughts



但是,还有其他几种方法可以解决日期问题,而无需将其修复到数据库中.例如,基于某个日期选择第N行也可能是可用的解决方案.



However there are several other ways to resolve the date problem without fixing it into the database. For example selecting Nth row based on some date could also be a usable solution.


您好 这将返回您过去的那天(2011年2月18日)的想法.

Hi This will return thoughts for the day (18-Feb-2011) that you passed.

SELECT * From Thought WHERE CONVERT(VARCHAR(10), ThoughtDate, 101) = '02/18/2011'  --[MM/DD/YYYY]




谢谢,
伊马德森(Imadhusen)




Thanks,
Imadhusen


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

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