Can anyone help?
I’m trying to build a basic forum. (and i mean basic, no competition to this mighty forum!)
Now this is how my Details View and Object Data Source looks…
<asp:DetailsView ID="dtvReply" runat="server" AutoGenerateRows="False" DataKeyNames="fpId" DataSourceID="odsReply" GridLines="None" DefaultMode="Insert" >
<Fields>
<asp:TemplateField>
<ItemTemplate></ItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txt_summary" CssClass="textbox" runat="server" Text='<%# Bind("fpSummary") %>'></asp:TextBox>
<%-- <asp:RequiredFieldValidator CssClass="error" ID="rfvfpSummary" ControlToValidate="txt_summary" Display="Dynamic" ForeColor="" ValidationGroup="valReplyValidationGroup" runat="server" Text="Please supply a Summary to your reply." ErrorMessage="Please supply a Summary to your reply."></asp:RequiredFieldValidator>--%>
<asp:TextBox ID="txt_comment" CssClass="textbox" runat="server" Height="200px" Columns="25" Text='<%# Bind("fpBody") %>'></asp:TextBox>
<%-- <asp:RequiredFieldValidator CssClass="error" ID="rfvfpComment" ControlToValidate="txt_comment" Display="Dynamic" ForeColor="" ValidationGroup="valReplyValidationGroup" runat="server" Text="Please supply your Comments." ErrorMessage="Please supply your Comments."></asp:RequiredFieldValidator>--%>
<asp:Button ID="but_submit" CssClass="button" runat="server" Text="Submit" PostBackUrl="#" CausesValidation="True" CommandName="Insert" ValidationGroup="valReplyValidationGroup"></asp:Button>
<asp:Label ID="lblDateTime" runat="server" Text='<%# Bind("fpDatePosted") %>' ></asp:Label>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsReply" runat="server"
InsertMethod="forum_INSERT_REPLY" TypeName="dotnet.BLL.bllForum">
<InsertParameters>
<asp:Parameter Name="fpSummary" Type="String" />
<asp:Parameter Name="fpUsername" Type="String" DefaultValue="TIMMY" />
<asp:Parameter Name="fpBody" Type="String" />
<asp:Parameter Name="fpDatePosted" Type="DateTime" />
<asp:Parameter Name="fpTopicId" Type="Int32" DefaultValue="1" />
<asp:Parameter Name="fpLive" Type="Boolean" DefaultValue="True" />
</InsertParameters>
</asp:ObjectDataSource>
NOW… as you can see its very simple, just wondering how I go about passing in the current Date and Time (ie.1/1/1753 12:00:00 AM) - its going into a MS SQL Server database btw.
I thought I should create a label (named lblDateTime) Bind it to the parameter / field and create in the partial class behind in the
dtvReply_ItemInserting sub the code to pass in todays date…
like so…
Protected Sub dtvReply_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dtvReply.ItemInserting
Dim lblDateTime As Label
lblDateTime = CType(dtvReply.FindControl("lblDateTime"), Label)
lblDateTime.Text = Date.UtcNow
End Sub
(note i have tired Date.Now as well as Date.UtcNow, I tired Utc as I read somewhere that it includes the time with the date - which MS SQL requires.)
Anyway I get the following error…
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Can anyone set me right?
Thanks,
Tim