Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 19th, 2013, 05:59 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default Database default value

Hi Folks, I am trying to enter a default value (todays date) in my database by setting (getdate()) in the default value or binding in the Date column properties - but it is not running.

I am using a details view with a associated sqldata source and i have generated the usual insert / delete commands.

Any ideas of where I am going wrong,

Thanks
Mark
Reply With Quote
  #2 (permalink)  
Old February 19th, 2013, 07:17 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you define "it's not running"? Do you get an error?

It's important to realize that defaults only work when your SQL statement is not supplying a value. So when you've set up your data controls for that date column, SQL will take the value supplied by the control, not it's default.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following 2 Users Say Thank You to Imar For This Useful Post:
markhh (February 20th, 2013)
  #3 (permalink)  
Old February 20th, 2013, 03:55 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar, what I mean is that when I insert a new record the date field which I am trying to insert automatically using (getdate()) is not inserted - no errors are reported and the field remains null. What about using an event like ItemInserting would this be another way around it,

Regards
Mark
Reply With Quote
  #4 (permalink)  
Old February 20th, 2013, 04:31 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

It sounds like your UI is still supplying a value, even though it's null. A default only works when you're not supplying a value (even a null value) for the column with the default. So, let's say you have a table with an Id, a Name and a CreationDate, the following would trigger the default on CreationDate:

INSERT INTO SomeTable (Id, Name) VALUES (1, 'Something')

but this wouldn't:

INSERT INTO SomeTable (Id, Name, CreationDate) VALUES (1, 'Something', null)

If you have a data control with a parameter for CreationDate, ASP.NET sends null to the database which results in null, an not the result of GetDate() to be inserted.

Either remove the column / parameter from your data control, or replicate the default value in your code in one of the data events by supplying a value explicitly.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old February 21st, 2013, 09:22 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Thanks again Imar, some very good points.

Regards
Mark
Reply With Quote
  #6 (permalink)  
Old April 25th, 2013, 04:38 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar, your solution works fine (removing the field in question from the sqldatasource).

Another query I have searched but I cannot find how to insert a value or text into my database using one of the data events (such as additional comments). Any ideas,

Regards
Mark
Reply With Quote
  #7 (permalink)  
Old April 25th, 2013, 04:41 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Mark,

I don't understand the question. Can you elaborate?

Also, can you please start a new thread for each new topic?

Thanks,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code for Chpt.2-Wrox File Share is missing Default.aspx and Default.aspx.vb bzoni BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 October 23rd, 2009 02:39 PM
Cannot open user default database KamalRaturi ASP.NET 2.0 Professional 2 October 25th, 2006 10:43 AM
DTS Package - Default database error interlogics SQL Server DTS 0 December 9th, 2005 06:30 AM
ODBC Default Database peace Access VBA 0 September 25th, 2004 04:45 PM
ODBC Default Database peace Access 0 September 25th, 2004 04:32 PM



All times are GMT -4. The time now is 07:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.