0

我遇到了SqlDataSource对象问题,并让它在 SQL Server (2005) 中存储日期和时间。

数据源(我已经排除了正常工作的位):

<asp:SqlDataSource ID="dataRequest" runat="server" 
  SelectCommand="request_select"  SelectCommandType="StoredProcedure" 
  InsertCommand="request_insert"  InsertCommandType="StoredProcedure" 
  UpdateCommand="request_update"  UpdateCommandType="StoredProcedure"
  >
    <SelectParameters>
        <!-- This section work fine -->
        <asp:QueryStringParameter Name="requestid"  Type="Int32" QueryStringField="requestid" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="requestid"             Type="Int32"    />
        <!-- Lots of parameters here that work fine -->
        <asp:Parameter Name="date_new_req"          Type="DateTime" />
        <asp:Parameter Name="date_new_acc"          Type="DateTime" />
        <asp:Parameter Name="date_quote_req"        Type="DateTime" />
        <asp:Parameter Name="date_quote_acc"        Type="DateTime" />
        <asp:Parameter Name="date_bh_approve_req"   Type="DateTime" />
        <asp:Parameter Name="date_bh_approve_acc"   Type="DateTime" />
        <asp:Parameter Name="date_work_req"         Type="DateTime" />
        <asp:Parameter Name="date_work_acc"         Type="DateTime" />
        <asp:Parameter Name="date_complete_req"     Type="DateTime" />
        <asp:Parameter Name="date_complete_acc"     Type="DateTime" />
        <asp:Parameter Name="date_declined_req"     Type="DateTime" />
        <asp:Parameter Name="date_declined_acc"     Type="DateTime" />
        <asp:Parameter Name="date_bh_declined_req"  Type="DateTime" />
        <asp:Parameter Name="date_bh_declined_acc"  Type="DateTime" />
        <asp:Parameter Name="date_archived_req"     Type="DateTime" />
        <asp:Parameter Name="requestor_ntlog"       Type="String"   />
    </UpdateParameters>
    <InsertParameters>
        <!-- This section works fine -->
    </InsertParameters>
</asp:SqlDataSource>

日期只是显示在文本框中,旁边有一个“戳记”按钮,用于在其中戳记当前日期和时间。每个文本框都是绑定到 的数据SqlDataSource并位于FormView. 更新时,正确提交了 的其余FormView信息,包括文本字段、数字字段(来自文本框和 DDL)和复选框。

<asp:FormView ID="requestProcessing" runat="server" DefaultMode="ReadOnly"
    DataSourceID="dataRequest" DataKeyNames="requestid"
    CssClass="editPanel" BorderStyle="None" EnableViewState="true">

    <!-- There's loads of stuff within the FormView, but I've omitted it as it's irrelevant to this issue, but will post if necessary -->

    <table class="dateTable" cellpadding="0" cellspacing="0">

    <tbody>
        <tr>
            <td class="prompt">
                <asp:Label   ID="date_new_req_update_label" runat="server" Text="New job request" AssociatedControlID="date_new_req_update" /><br />
            </td>
            <td>
                <asp:TextBox runat="server" ID="date_new_req_update" Text='<%# Bind("date_new_req") %>' CssClass="dataEntry" MaxLength="25" />
                <a href="javascript:stampNow('requestProcessing_date_new_req_update')" class="dateButton">stamp</a>
            </td>
            <td>
                <asp:TextBox runat="server" ID="date_new_acc_update" Text='<%# Bind("date_new_acc") %>' CssClass="dataEntry" MaxLength="25" />
                <a href="javascript:stampNow('requestProcessing_date_new_acc_update')" class="dateButton">stamp</a>
            </td>
        </tr>                
        <tr id="row2" runat="server">
            <td class="prompt">
                <asp:Label   runat="server" ID="date_quote_req_update_label" Text="Date of quote" AssociatedControlID="date_quote_req_update" />
            </td>            
            <td>
                <asp:TextBox runat="server" ID="date_quote_req_update" Text='<%# Bind("date_quote_req") %>' CssClass="dataEntry" MaxLength="25" />
                <a href="javascript:stampNow('requestProcessing_date_quote_req_update')" class="dateButton">stamp</a>
            </td>
            <td>
                <asp:TextBox runat="server" ID="date_quote_acc_update" Text='<%# Bind("date_quote_acc") %>' CssClass="dataEntry" MaxLength="25" />
                <a href="javascript:stampNow('requestProcessing_date_quote_acc_update')" class="dateButton">stamp</a>
            </td>
        </tr>                
        <tr id="row3" runat="server">
            <td class="prompt">
                <asp:Label   runat="server" ID="date_bh_approve_req_update_label" Text="Budget holder alerted" AssociatedControlID="date_bh_approve_req_update" />
            </td>            
            <td>
                <asp:TextBox runat="server" ID="date_bh_approve_req_update" Text='<%# Bind("date_bh_approve_req") %>' CssClass="dataEntry" MaxLength="25" />
                <a href="javascript:stampNow('requestProcessing_date_bh_approve_req_update')" class="dateButton">stamp</a>
            </td>
            <td>
                <asp:TextBox runat="server" ID="date_bh_approve_acc_update" Text='<%# Bind("date_bh_approve_acc") %>' CssClass="dataEntry" MaxLength="25" />
                <a href="javascript:stampNow('requestProcessing_date_bh_approve_acc_update')" class="dateButton">stamp</a>
            </td>
        </tr>
        <!-- I've omitted a lot of the dates here as they've all been tested and give the same result ... nothing! -->
    </tbody>

    </table>

</asp:FormView>

web.config我已经包括了一个专门针对英国的全球化路线(以防万一)。

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB" uiCulture="en-GB"/>

由更新过程发起的唯一代码向请求者发送邮件:

Private Sub UpdateComplete(ByVal sender As Object, ByVal e As FormViewUpdatedEventArgs) Handles requestProcessing.ItemUpdated
    If CType(requestProcessing.FindControl("mailUser"), CheckBox).Checked Then
        Dim body As New StringBuilder()
        With e.NewValues
            'Notify the user of changes to the current request...
            body.Append("<p>Changes have been made to your job request (")
            body.Append(.Item("requestid").ToString())
            body.Append(").</p>")
            body.Append("<p>If you would like to review the changes to your job, please click ")
            body.Append("<a href='")
            body.Append(System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority))
            body.Append("/default.aspx?requestid=")
            body.Append(.Item("requestid").ToString())
            body.Append("&mode=select'>Click this link to view your job.</a>")
            body.Append("<p>With kind regards,<br /><strong>The Minor New Works Team</strong></p>")
            Functions.BuildEmail(CType(.Item("requestid"), Int32), True, False, "", _
               "Changes have been made to your job request", body.ToString(), _
               Functions.LocalMailFlagsEnum.BasicBody Or Functions.LocalMailFlagsEnum.VerboseSubject)
            'Check to see if budget holder acceptance should be requested...
            If Not .Item("date_bh_approve_req") Is Nothing AndAlso _
               Not e.OldValues.Item("date_bh_approve_req") Is Nothing AndAlso _
               .Item("date_bh_approve_req").ToString() <> "" AndAlso _
               e.OldValues.Item("date_bh_approve_req").ToString() = "" Then
                Functions.NotifyBudgetHolder(CType(.Item("requestid"), Int32))
            End If
        End With
    End If
End Sub

我已经测试了拉取和推送信息所需的每个存储过程,它们工作正常,产生了所需的结果。另外,我添加了一个日志记录例程来捕获传递给存储过程的参数;在手动执行时,所有参数都记录到日志表中,而在从 ASP.NET 页面执行时,日期被排除在外。

如果有人能对这个问题有所了解或遇到过类似的问题,我很想听听。

-- 编辑 -- 这是 ASP.NET 3.5

4

1 回答 1

0

行。这花了一段时间,但我发现了问题。

出于某种原因,ASP.NET 不喜欢我放置TextBox元素的表格格式。

现在我将把它们拿出来玩一下这个格式。桌子不是必须的;这只是我想以表格形式呈现这些数据的方式,所以我一有时间就会整理出来。

- 编辑 -

为了更进一步,我在FormView控件中尝试了几种不同格式的表格,每次都发现完全相同的问题,即使使用 ASP.NET 自己的Table控件也是如此。

于 2013-04-22T08:51:53.557 回答