如何使用C#在数据库中填充自动生成日期 [英] How to fill auto generate date in database using C#

查看:218
本文介绍了如何使用C#在数据库中填充自动生成日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子名字是收据



表格有以下栏目

acno,name,dueamt,no.of.days, dubate。



i需要使用自动生成日期填写截止日期,日期从02/02/2018开始到100天后。

请帮帮我.............



我尝试了什么:



i有创建自动生成ID的想法,但我不知道如何在c#中创建自动增量日期。

解决方案

< blockquote>如果截止日期始终是发票日期的100天(这在实践中是不寻常的,不同的客户通常会有不同的付款条款),那么最简单的方法是使用SQL Computed列:在表中指定计算列| Microsoft Docs [ ^ ]

的规范(DATEADD(day,( 100) ),[InsertDate]))

会这样做。



但我会在C#中使用DateTime.AddDays相反,因为它允许以后的灵活性。


my table name is receipts

the table has the following columns
acno,name,dueamt,no.of.days,duedate.

i need to fill the due date using auto generate date the date is started from 02/02/2018 to after 100 days.
please help me.............

What I have tried:

i have a idea to create auto generate id,but i don't know how to create auto increment date in c#.

解决方案

If the due date is always 100 days from invoice date (which would be unusual in practice, different customers would normally different payment terms) then teh sikmplest way is to use an SQL Computed column: Specify Computed Columns in a Table | Microsoft Docs[^]
A specification of

(DATEADD(day,(100),[InsertDate]))

would do it.

But I'd do it in C# using DateTime.AddDays instead as it allows for flexibility later.


这篇关于如何使用C#在数据库中填充自动生成日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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