简体   繁体   English

从SQL Server Express表列到数据集的默认值?

[英]Default values from SQL Server Express table column to Dataset?

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. 我正在关注Microsoft的Data Video Series上的Forms。 However, I am creating a databse, different from the one created in the videos. 但是,我创建的是数据库,不同于视频中创建的数据库。

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. 在其中一个表中,我希望将当前日期/时间插入到date列中,因此我使用getdate()函数作为默认值,该函数是使用SQL Server Management Studio设置的。 When I insert new rows in this table using SQL Server Management Studio, the said column is updated fine. 当我使用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. 谢谢。

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

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. 由于您是使用GETDATE()设置列的默认值的,所以我什至在查询中都没有该列,所以让SQL继续为您设置它。 I hope I'm understanding your question correctly 希望我能正确理解您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM