Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting SQL Server default values into Dataset (Especially DateTime)

Status
Not open for further replies.

nells1

Programmer
Mar 17, 2003
28
CA
Hi

My VB.NET application fills it's dataset out of a SQL Server database. I know that the Default Values from the database do not copy across to the dataset so I have started looking for other ways to do this.

I have found that the default values are stored in the SQL Server System Tables, and can be retrieved using....

Code:
SELECT
    dbo.sysobjects.name, dbo.syscomments.text
FROM
    dbo.sysobjects 
    INNER JOIN
    dbo.syscomments 
    ON dbo.sysobjects.id = dbo.syscomments.id
WHERE
    (dbo.sysobjects.xtype = 'D') 
ORDER BY 
    dbo.sysobjects.name

Which works perfectly for most datatypes. DateTime however are not so good.

Heres where my questions come in.


1) How do you guys/girls handle getting the default dates from your databases??


It must be a common problem, and I wouldn't like to have to hard code them in incase the business logic changes, granted, thats not going to happen often, but I want to do things as correctly as I can. So any advise on how you all handle your default values would be greatly appreciated.




2) How do you set a DateTime datacolumn's default value to the exact time the new row is created??

I would have thought:
Code:
datacolumn.DefaultValue = Now()
But when I do this on application start and then change my computer time to tomorrow, then create a new row, the new row has today's date.

Is my test flawed??? or does setting the column's default value to Now() make the default value the actual date value of Now ie (7/29/2004 13:20:00)??


Thank you in advance for any help you can offer.

Hope you're all having a good week!
Cheers
Nells
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top