Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-16
3
Medium Priority
?
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 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