Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-07-16
3
Medium Priority
?
352 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

783 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