Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now