且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#在数据库中填充自动生成日期

更新时间:2023-01-29 15:33:40

如果截止日期始终是发票日期的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.