更新 AccessDatasource 什么也不做但没有错误 [英] Update of AccessDatasource does nothing but has no error

查看:55
本文介绍了更新 AccessDatasource 什么也不做但没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UPDATE 命令无法更改表中的任何日期,而非常相似的 SELECT 和 DELETE 命令起作用.当我将 UpdateParameters 更改为无效选项时,命令背后的代码会引发错误,但当参数正确时,什么也不会发生.

My UPDATE command fails to change any date in the table while very similar SELECT and DELETE commands work. When I change the UpdateParameters to invalid choices, the code behind command throws an error, but when the parameters are correct, nothing hapens.

激活 DELETE 的代码(有效)

Code behind to activate DELETE (which works)

protected void Button2_Click(object sender, EventArgs e)
{
    this.AccessDataSource6.Delete();
}

激活UPDATE的代码(似乎对数据有任何影响)

Code behind to activate UPDATE (which does seem to have any effect on the data)

protected void Button1_Click(object sender, EventArgs e)
{
    this.AccessDataSource6.Update();
} 

AccessDatasource,它的 SQL 命令和参数

The AccessDatasource, its SQL commands and parameters

   <asp:AccessDataSource ID="AccessDataSource6" runat="server" DataFile="~/App_Data/ASPNetDB.mdb" 
    SelectCommand="SELECT [PracticeDate], 
                          [StartTime], 
                          [EndTime], 
                          [Division], 
                          [TeamStr], 
                          [FieldName] 
    FROM [vw_fbScheduleFull]
    WHERE (([LocationID] = ?) 
       AND ([DayName] = ?) 
       AND ([PracticeDate] &gt;= ?) 
       AND ([PracticeDate] &lt;= ?) 
       AND ([StartTime] = ?))
    ORDER BY [PracticeDate], [FieldName]"

    UpdateCommand="UPDATE fbPracticeSlot 
    SET StartTime = ?, EndTime = ?
    WHERE ID IN (
       SELECT [PracticeSlotID] 
       FROM [vw_fbScheduleFull] 
       WHERE (([LocationID] = ?) 
          AND ([DayName] = ?) 
          AND ([PracticeDate] &gt;= ?) 
          AND ([PracticeDate] &lt;= ?) 
          AND ([StartTime] = ?))
       )" 

   DeleteCommand="DELETE FROM fbPracticeSlot 
    WHERE ID IN (
       SELECT [PracticeSlotID] 
       FROM [vw_fbScheduleFull]
       WHERE (([LocationID] = ?) 
          AND ([DayName] = ?) 
          AND ([PracticeDate] &gt;= ?) 
          AND ([PracticeDate] &lt;= ?) 
          AND ([StartTime] = ?)) 
       )">

<SelectParameters>
       <asp:ControlParameter ControlID="DropDownListLocation" Name="LocationID" PropertyName="SelectedValue" Type="Int32" />
       <asp:ControlParameter ControlID="DropDownListDOW" Name="DayName" PropertyName="SelectedValue" Type="String" />
       <asp:ControlParameter ControlID="DropDownListStartDate" Name="PracticeDate" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListEndDate" Name="PracticeDate2" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListStartTime" Name="StartTime" PropertyName="SelectedValue" Type="DateTime" />
</SelectParameters>

<UpdateParameters>
       <asp:ControlParameter ControlID="DropDownListNewStart" Name="NewStartTime" PropertyName="SelectedValue" Type="DateTime" />                  
       <asp:ControlParameter ControlID="DropDownListNewEnd" Name="NewEndTime" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListLocation" Name="LocationID" PropertyName="SelectedValue" Type="Int32" />
       <asp:ControlParameter ControlID="DropDownListDOW" Name="DayName" PropertyName="SelectedValue" Type="String" />
       <asp:ControlParameter ControlID="DropDownListStartDate" Name="PracticeDate" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListEndDate" Name="PracticeDate2" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListStartTime" Name="StartTime" PropertyName="SelectedValue" Type="DateTime" />
</UpdateParameters>

<DeleteParameters>
       <asp:ControlParameter ControlID="DropDownListLocation" Name="LocationID" PropertyName="SelectedValue" Type="Int32" />
       <asp:ControlParameter ControlID="DropDownListDOW" Name="DayName" PropertyName="SelectedValue" Type="String" />
       <asp:ControlParameter ControlID="DropDownListStartDate" Name="PracticeDate" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListEndDate" Name="PracticeDate2" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListStartTime" Name="StartTime" PropertyName="SelectedValue" Type="DateTime" />
</DeleteParameters>

</asp:AccessDataSource>

请帮助我理解为什么更新没有改变数据.

Please help me understand why the update is not changing data.

似乎我要么需要编写带有硬编码参数的 UpdateCommands 来更改值,要么为我想要执行的每个更新编写一个 DeleteCommand 和 InsertCommand.请帮我找到避免这种混乱的方法.

It seems that I either need to write UpdateCommands with hard coded parameters for the values to change or write a DeleteCommand and InsertCommand for each update that I want to perform. Please help me find some way to avoid that sort of kludge.

推荐答案

通常有效的 SQL Update 语句会失败而不会出错,因为没有记录匹配您的 WHERE 条件.你有没有在 Button_Click 事件上设置断点并查看参数的值?

Usually a valid SQL Update statement fails without error because no records match your WHERE condition. Have you set a breakpoint on the Button_Click event and looked at the value of the parameters?

这篇关于更新 AccessDatasource 什么也不做但没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆