DateTime.Now () ?

I am using a gridview that is connected to a table adpater. On Insert of a new row I would like for a specific date column to be updated with the system date or the DateTime.Now. I have attempted to set the default value to DateTime.Now() and that did not work for me. Does anyone have a solution for this?

Thanks!


Jeff
0
jthomas8946
5/4/2009 1:39:30 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

16 Replies
1118 Views

Similar Articles

[PageSpeed] 14

 You can use trigger in this case.


Thanks
Pankaj Gohel

Please Mark as Answer if you find the post useful.
0
pankajgohel
5/4/2009 1:50:35 PM

convert that field to template field first, then set the default value to dateTime.now.

in dataset, for insert, use the default value in your query.  if you use stored procedure, you don't need to add the date field to the input parameters. 


Lynn

Please mark replies that have helped you as answers.

http://www.sis.pitt.edu/~lberan/collegeMathTutorPittsburgh/index.html
0
lberan
5/4/2009 2:02:17 PM

convert that field to template field first, then set the default value to dateTime.now.

in dataset, for insert, use the default value in your query.  if you use stored procedure, you don't need to add the date field to the input parameters. 

 


Lynn

Please mark replies that have helped you as answers.

http://www.sis.pitt.edu/~lberan/collegeMathTutorPittsburgh/index.html
0
lberan
5/4/2009 2:04:58 PM

lberan:

convert that field to template field first, then set the default value to dateTime.now.

in dataset, for insert, use the default value in your query.  if you use stored procedure, you don't need to add the date field to the input parameters. 

 

 
I am using a table adapter (dataset). I am unaware of how to complete this task, can you provide me with a sample?
 
Thanks!

Jeff
0
jthomas8946
5/4/2009 2:50:47 PM

please post you dataset query for insert and i'll modify it for you


Lynn

Please mark replies that have helped you as answers.

http://www.sis.pitt.edu/~lberan/collegeMathTutorPittsburgh/index.html
0
lberan
5/4/2009 2:56:47 PM

I am not sure which Insert statement you wanted.

From Dataset:

<InsertCommand>

<DbCommand CommandType="Text" ModifiedByUser="false">

<CommandText>INSERT INTO [dbo].[TaskList] ([TaskLeader], [Description], [Notes], [CreationDate], [DeadlineDate], [Completed]) VALUES (@TaskLeader, @Description, @Notes, @CreationDate, @DeadlineDate, @Completed)</CommandText>

<Parameters>

<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@TaskLeader" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="TaskLeader" SourceColumnNullMapping="false" SourceVersion="Current" />

<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Description" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Description" SourceColumnNullMapping="false" SourceVersion="Current" />

<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Notes" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Notes" SourceColumnNullMapping="false" SourceVersion="Current" />

<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="DateTime" Direction="Input" ParameterName="@CreationDate" Precision="0" ProviderType="DateTime" Scale="0" Size="0" SourceColumn="CreationDate" SourceColumnNullMapping="false" SourceVersion="Current" />

<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="DateTime" Direction="Input" ParameterName="@DeadlineDate" Precision="0" ProviderType="DateTime" Scale="0" Size="0" SourceColumn="DeadlineDate" SourceColumnNullMapping="false" SourceVersion="Current" />

<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Boolean" Direction="Input" ParameterName="@Completed" Precision="0" ProviderType="Bit" Scale="0" Size="0" SourceColumn="Completed" SourceColumnNullMapping="false" SourceVersion="Current" />

</Parameters>

</DbCommand>

</InsertCommand>

 

From aspx page:

<InsertParameters>

<asp:Parameter Name="TaskLeader" Type="String" />

<asp:Parameter Name="Description" Type="String" />

<asp:Parameter Name="Notes" Type="String" />

<asp:Parameter Name="CreationDate" Type="DateTime" DefaultValue="DateTime.Now()" />

<asp:Parameter Name="DeadlineDate" Type="DateTime" />

<asp:Parameter Name="Completed" Type="Boolean" />

</InsertParameters>


Jeff
0
jthomas8946
5/4/2009 3:02:38 PM

 

  1.  change this: <CommandText>INSERT INTO [dbo].[TaskList] ([TaskLeader], [Description], [Notes], [CreationDate], [DeadlineDate], [Completed]) VALUES (@TaskLeader, @Description, @Notes, @CreationDate, @DeadlineDate, @Completed)</CommandText>

 

to:

<CommandText>INSERT INTO [dbo].[TaskList] ([TaskLeader], [Description], [Notes], [CreationDate], [DeadlineDate], [Completed]) VALUES (@TaskLeader, @Description, @Notes, DateTime.Now(), @DeadlineDate, @Completed)</CommandText>

 

2. delete this:

<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="DateTime" Direction="Input" ParameterName="@CreationDate" Precision="0" ProviderType="DateTime" Scale="0" Size="0" SourceColumn="CreationDate" SourceColumnNullMapping="false" SourceVersion="Current" />

3. delete this:

<asp:Parameter Name="CreationDate" Type="DateTime" DefaultValue="DateTime.Now()" />


Lynn

Please mark replies that have helped you as answers.

http://www.sis.pitt.edu/~lberan/collegeMathTutorPittsburgh/index.html
0
lberan
5/4/2009 3:26:05 PM

Thanks for the response. I am recieving the following error:

ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Insert' that has parameters: TaskLeader, Description, Notes, DeadlineDate, Completed, CreationDate.

Any idea's?

Thanks again!


Jeff
0
jthomas8946
5/4/2009 3:56:32 PM

sorry about that.  DateTime.Now() is a asp.net function. 

in a sql query, getdate() should be used.


Lynn

Please mark replies that have helped you as answers.

http://www.sis.pitt.edu/~lberan/collegeMathTutorPittsburgh/index.html
0
lberan
5/4/2009 3:59:38 PM

Did you read pankajgohel response?  It's, in my opinion, the easiest and cleanest solution.

Edit: not only that, but if someone were to insert a record directly from the DB, you would still be populating the date.


C# <---> VB.Net Translator
0
MetalAsp
5/4/2009 4:12:35 PM

MetalAsp.net is right.  there are better solutions.   besides trigger, you could set the default value for the field in the database. 


Lynn

Please mark replies that have helped you as answers.

http://www.sis.pitt.edu/~lberan/collegeMathTutorPittsburgh/index.html
0
lberan
5/4/2009 4:19:51 PM

I would like to thank everyone for your responses.

Lynn: I was still recieving an error after I did what you suggested.

With that said, I decided to try a trigger on the insert of a new record for that particular table. The problem I am running into now is that the date is being inserted into a new record instead of the record that was created. My knowledge on trigger's is very limited. Does anyone have an idea why this is not working for me? I attempted to add a "where" clause, but it would not allow it.

Trigger:

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TRIGGER trig_Log_Insert_TaskList ON dbo.TaskList

 

For INSERT

AS

BEGIN

SET NOCOUNT ON;

Insert into TaskList (CreationDate) Values (getdate())

END

Thanks again for all your help!


Jeff
0
jthomas8946
5/4/2009 6:22:05 PM

i honestly don't know how trigger works in this situation.  However,  nothing can be simpler than setting default value for creationDate.  why don't you give it a try?


Lynn

Please mark replies that have helped you as answers.

http://www.sis.pitt.edu/~lberan/collegeMathTutorPittsburgh/index.html
0
lberan
5/5/2009 1:29:41 AM

Try this

 

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO
CREATE TRIGGER trig_Log_Insert_TaskList ON dbo.TaskList

 
For INSERT

AS

BEGIN

SET NOCOUNT ON;

Update TaskList SET CreationDate = getdate() where ID In (Select ID FROM inserted)

END

 

 

Where ID is the primary key of Table TaskList


Thanks
Pankaj Gohel

Please Mark as Answer if you find the post useful.
0
pankajgohel
5/5/2009 5:21:05 AM

Simple you can alter your table as  

ALTER TABLE [TableName] WITH NOCHECK
ADD CONSTRAINT [Df_tblname_colName] DEFAULT DefaultValue FOR colName

 In your case

ALTER TABLE TaskList WITH NOCHECK
ADD CONSTRAINT Df_tblname_CreationDate DEFAULT 'getdate()' FOR CreationDate

By this when ever you add a column to your table and not specify this creationdate value its default value is assigned.

If you want the default value to be assigned dont pass the value and it would insert the default value.

Hopefully this must solve your problem. strictly no need for triggers in this case 

 


Please Mark as Answer if this reply helps you :)
0
TechFriend
5/5/2009 6:13:55 AM

Simple you can alter your table as

ALTER TABLE [TableName] WITH NOCHECK ADD CONSTRAINT [Df_tblname_colName] DEFAULT DefaultValue FOR colName

n your case ALTER TABLE TaskList WITH NOCHECK ADD CONSTRAINT Df_tblname_CreationDate DEFAULT 'getdate()' FOR CreationDate

By this when ever you add a column to your table and not specify this creationdate value its default value is assigned. If you want the default value to be assigned dont pass the value and it would insert the default value.

Hopefully this must solve your problem. strictly no need for triggers in this case


Please Mark as Answer if this reply helps you :)
0
TechFriend
5/5/2009 6:16:13 AM
Reply:

Similar Artilces:

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

As DateTime = DateTime.Now....
Hello: I have a process that runs and would like to preserve the computer time inside of the variable when the process finishes. Using this method Dim dtDateTimeVar As DateTime = DateTime.Now the information inside the variable does not stay static and keeps changing with the time... what can I do to work around this?Need ASP.NET web hosting? Private Message me for a free quote. I have even tried something like this... Dim dtDateTimeVar as DateTime = DateTime.Now Dim varOldTime as String varoldtime = dtDateTimeVar It still gets the current time instead of the...

datetime.now() and datetime.now().addmonths()..insert code run before.. but it doesnt run now... i have no done anything.. why dont it run itself ?
hi datetime.now() and datetime.now().addmonths().. it run before.. but it doesnt run now... i have no done anything.. why doesnt it run now ? my datatype is datetime.. what can problem be ? sds.InsertParameters.Add("ilanbaslangictarihi", DateTime.Now()) hello friends when i change 14.06.2008 to 10.06.2008 from my computer, inserting run for datetime.now() but when i change 10.06.2008 to 14.06.2008 from my computer.. inserting doesnt run for datetime.now() Also when i enter {0:dd/MM/YYYY hh:mm:ss} to formatstring of edit column of gridview, gridview display 33.06.2008 1...

datetime.now and server datetime ?
hi how can i get datetime of server without storedprocedure ? my code is below in *.aspx.vb DateTime.Now() ThanksMark as me if my question or my answer can be helpful for you :) oguzkaygun: hi how can i get datetime of server without storedprocedure ? my code is below in *.aspx.vb DateTime.Now() Thanks Dim dt As Date = Date.Now Dim strtime As String = dt.ToShortTimeString()  MAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets  I don't see what's wrong with what you have. The code you posted does exac...

How do the different data presentation controls equate in ADO.net?
How does Visual Studio create ado.net equivalents of the datagrid's and gridview's columns and rows?  I am assuming they make a DataRow for each of the rows.  Am I on the right track with this?Is the table created by gridview basically a dataset from ADO.net?  Can anyone offer any guidance with this?Thanks to everyone that has ever helped me with any posts. Hi newbie2C#, The row in datagrid is called DataGridItem and in gridview is called GridViewRow. They are all inherits TableRow Class. DataRow is only one kind of row in GridView control. There are many other t...

Trouble controlling .net controlls with CSS
 I am trying to control the :hover css property on <asp: Button> controls. Basically the css is working correctly to set the initial look of the button, but nothing is happening when I hover over the button. Here is my code:CSS:.sidebarButton{    width: 168px;     height: 45px;     background-color: #666666;     text-align: left;    font-weight: bold;    font-family: Century Gothic;    font-size: 13pt;    color: White;    border-style: none;  ...

ajax control in data presentation controls
can i add ajax controls (MaskedEdit) to presentation controls (dataGrid, dataForm)?? Hi,of course. But keep in mind that those controls are extenders, so you append them to an existing control. Just convert your GridView / DetailsView-fields into templated fields and add the extender you'd like to use to the controls.RegardsMarco Buerckel Don't forget to mark posts that were helpful as answers. Actually, if you looked at the source code for the Masked Edit Extender, you'd see  [TargetControlType(typeof(TextBox))]Meaning, targeting any control type other than textboxes...

Error "using DateTime.Now in user control's page render event getting refreshed though placed in UpdatePanel
Hi All I have two user control with a calendar control and within the page render event I am just writing writer.WriteLine(DateTime.Now.ToString() in both the contols contols are  placed in updatePanel .I am hosting these control in an aspx page .Whenever I am clicking on any of the calendar's month it is not changing other calendar's month but it is refreshing the time for both user control.Code snippet.  <uc:Order id="UserControl1" runat="server"></uc:Order> <uc:Order id="OrderDetail" runat="server...

What is the real difference between Server Controls and .NET controls?
This was a class discussion question and I'd like to know, what exactly are the differences? Is there a clear answer? .NET framework controls are server controls. The only difference that I can think of is that the .NET controls are part of the FCL (Framework Class Library). HTH,RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

Making the .NET calendar control as a floating control
Hi, I need to implement the .NET calendar control as a floating control. Is it possible to do that? If so, can you let me know how to do that?With Regards,Saravana Kumar M R  You could use the calendar extender control in the AJAX control toolkit. You can download the toolkit here, and there is a sample here.My Blog...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET- http://www.aspnetzone.de/blogs/peterbuch...

.NET DateTime and SQL Server DateTime problem
.NET DateTime and SQL Server DateTime problem  I have the following if statement in an SQL stored procedure: IF (@Image = 1 AND @DateTimeUploaded = (SELECT ImageMainDateTime FROM Images WHERE UserID = @UserID))   The value of the @DateTimeUpdated variable was taken from the ImageMainDateTime field when the data was requested by a ASP.NET webpage and is passed back here when that page is submitted so I can compare what the DateTime was when the data was requested with what it is now, in other words I’m doing a concurrency check (I can’t use TimeStamp for many reasons, ...

Issue when converting XML dateTime to .NET DateTime
Hi, I am experiencing an issue when deserializing XML dateTime nodes in ASP.NET in some timezones. The construct 0001-01-01T00:00:00.0000000+ZZ:ZZ where ZZ:ZZ is the timezone offset for the timezone on the current system should produce a DateTime value equalling the constant DateTime.MinValue when converted. This works some of the time, such as for the Paris time offset of +1: (CDate("0001-01-01T00:00:00.0000000+01:00") = DateTime.MinValue) = True But does not work for Sydney time offset of +10: (CDate("0001-01-01T00:00:00.0000000+10:00") = DateTime....

DW control in VB. NET custom control
Hi Just attempting to investigate some DW.NET aspects. In regards to building a ancestor object with VB.NET, why is when I create a datawindowcontrol custom control that any reference to it is like (assuming that u_dw is the name of the DW control): custom_control.u_dw.DatawindowObject = "myDW" instead of simply: u_dw.DatawindowObject = "myDW" If I create a .NET custom control with a button on it, I can directly reference the button's methods and properties without having to qualify it with the custom control's name. When I was developing with po...

Architecture: .Net Controls vs. Custom Controls
I'm interested in managing users. i.e. Logins and profiles, etc.My question is, should I be using things like the Login control or should I program these from scratch? I dont like the fact that .NET creates so many things for me. This level of abstraction terrifies me and it feels like I have no control over the code .I've done a few huge sites in Classic ASP (million-hits-per-day type sites) and I'm not sure how robust certain controls are, or when to use them.Is, for example, the Login control aimed at newbies to .NET? Should it be used for the larger projects with thousands of...

Web resources about - DateTime.Now () ? - asp.net.presentation-controls

Is there a JQuery plugin to convert UTC datetimes to local user timezone?
If I have a tag: &lt;span class="utctime"&gt;2010-01-01 11:30 PM&lt;/span&gt; I would like a jquery script or plug in to convert every utctime ...


Targetprocess 3.7.3: Epic unit for Bug/Story cards, new DateTime functions in Webhook plugin
Webhook plugin supports new DateTime functions AddDays(DateTime date, int days) – Returns a new date with the number of days added. The number ...

Common Pitfalls when working with DateTime’s
In .NET, the DateTime structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you ...

Parsing Twitter Date format to .Net DateTime
Recently when I needed to parse the twitter datetime format into a .Net DateTime I found this post on the web showing how to do it. However, ...

C Sharp (programming language) - Wikipedia, the free encyclopedia
(pronounced see sharp ) is a multi-paradigm programming language encompassing strong typing , imperative , declarative , functional , generic ...

1753 - Wikipedia, the free encyclopedia
Language: English Afrikaans አማርኛ العربية Aragonés Asturianu Aymar aru Azərbaycanca বাংলা Bân-lâm-gú Basa Banyumasan Беларуская ‪Беларуская (тарашкевіца)‬ ...

Coded Smorgasbord: Schizophrenic Haiku Comments and More
... writes Malcom StandardResponse UnSubscribeNewsletterUserAccount( string opTinGUID,string email, string sellingRegion, string source, DateTime ...

Limburg.be - Welkom op de site van de provincie Limburg - Welkom_op_de_site_van_de_provincie_Limburg
visit wonen werken leven ontspannen infopunt home op trefwoord contactpersonen wegwijs sitemap print deze pagina Je bent hier: limburg.be Contact ...

Simples Ideias. Por Nando Vieira.
Simples Ideias Siga-me no Twitter Junho/2012 Usando o Vagrant como ambiente de desenvolvimento no Windows http://simplesideias.com.br/usando ...

Resources last updated: 11/27/2015 3:25:12 PM