SQL Server Express表列到Dataset的默认值?

时间:2020-12-15 10:37:05

I am a new Database programming learner. I am using C# (.NET 3.5) along with SQL Server Express.

我是一名新的数据库编程学习者。我正在使用C#(。NET 3.5)和SQL Server Express。

I am following Forms over Data Video Series from Microsoft. However, I am creating a databse, different from the one created in the videos.

我正在关注Microsoft的数据视频系列表格。但是,我正在创建一个数据库,与视频中创建的数据库不同。

In one of the tables, I wanted the present date/time to be inserted in the date column, so I am using the getdate() function as default value, which I have set using SQL Server Management Studio. When I insert new rows in this table using SQL Server Management Studio, the said column is updated fine.

在其中一个表中,我希望将当前日期/时间插入日期列,因此我使用getdate()函数作为默认值,我使用SQL Server Management Studio设置了该值。当我使用SQL Server Management Studio在此表中插入新行时,所述列已更新。

However, when I use Windows form, and the auto-generated data grid for the dataset of this particular table, it does not update using the default value.

但是,当我使用Windows窗体以及此特定表的数据集的自动生成的数据网格时,它不会使用默认值进行更新。

I think I am missing something in this. If somebody could point me in the right direction, it would be really helpful. Thanks.

我想我错过了一些东西。如果有人能指出我正确的方向,那将是非常有帮助的。谢谢。

2 个解决方案

#1


When generating your query, don't pass the date as a parameter, or alternatively, pass DateTime.Now or DateTime.UTCNow as your "current time"

生成查询时,不要将日期作为参数传递,或者将DateTime.Now或DateTime.UTCNow作为“当前时间”传递

#2


Since you're setting the default value of the column using GETDATE() I would not even have that column in the query, let SQL keep setting it for you. I hope I'm understanding your question correctly

由于您使用GETDATE()设置列的默认值,我甚至不会在查询中使用该列,让SQL继续为您设置它。我希望我能正确理解你的问题

#1


When generating your query, don't pass the date as a parameter, or alternatively, pass DateTime.Now or DateTime.UTCNow as your "current time"

生成查询时,不要将日期作为参数传递,或者将DateTime.Now或DateTime.UTCNow作为“当前时间”传递

#2


Since you're setting the default value of the column using GETDATE() I would not even have that column in the query, let SQL keep setting it for you. I hope I'm understanding your question correctly

由于您使用GETDATE()设置列的默认值,我甚至不会在查询中使用该列,让SQL继续为您设置它。我希望我能正确理解你的问题