Solved

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

Posted on 2006-07-16
3
342 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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