Solved

How to plug system date/time value in Insert parameters?

Posted on 2006-07-16
3
343 Views
Last Modified: 2012-06-27
Hello - I've got a data entry page where I need to maintain input & update date-time stamps

I'm trying to set these in the parameters

        <InsertParameters>
            <asp:Parameter Name="MyField1" Type="Int32" />
            <asp:Parameter Name="MyField2" Type="String" />
            <asp:Parameter Name="MyField3" Type="String" />
                ...
            <asp:Parameter Name="InputOn" Type="DateTime" />
            <asp:Parameter Name="InputBy" Type="String" />

I tried:
            <asp:Parameter Name="InputOn" Type="DateTime" DefaultValue=Now() />

but that gets:
             Exception occurred: The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.  

(I know one way to get around this would be to set the Default value field back in the SQL Server table, but I need to set an accompanying "UpdateOn" field if/when the record is updated, so I might as well be consistent.)

And if it's not too much trouble, can anybody point me to a more advanced reference on how to set parameter values from sources other than form fields? Like Session variables, Profile values, etc...?

Thanks

Mark
0
Comment
Question by:mlagrange
  • 2
3 Comments
 
LVL 3

Expert Comment

by:mdg12
ID: 17117966
You might try doing something like
<asp:Parameter Name="InputOn" Type="DateTime" DefaultValue='<%# Now() %>' />
0
 

Author Comment

by:mlagrange
ID: 17118002
Thanks for the response, but just as typed, it got this error:
   Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.Parameter does not have a DataBinding event.

I played around with it a little:
   DefaultValue='<%=Now() %>'
and
   DefaultValue='<%=Now().ToString() %>'
both got this error:
   Exception occurred: String was not recognized as a valid DateTime.

0
 
LVL 3

Accepted Solution

by:
mdg12 earned 500 total points
ID: 17118066
You might consider leaving out the defaultvalue field in the page source, and instead add it in the codebehind
This is where you could do more advanced work with the parameters

//page_init is good place to do it, or you could capture the "Inserting" event of the datasource (just before insert occurs)
public void Page_Init()
{
  sqldatasource.InsertParameters["InputOn"].DefaultValue = DateTime.Now;
  // or set the value to sometihg from session... e.g. Session["paramName"]
}
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.net Move a class from Solution Items to a project 2 32
Footer for each row on Gridview 2 32
RLDC Reporting in Visual studio 11 30
asp.net web application 3 28
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question