【发布时间】:2019-05-29 19:04:01
【问题描述】:
我有 2 个存储客户喜欢和不喜欢的列表框。选择项目时,每个相应列表框下面有一个按钮,它们在一个中表示“删除类似”,并在另一个中“删除不喜欢”。当我单击任一按钮时,什么都没有发生。我的屏幕刚刚刷新。它工作了一段时间,我已经添加了一个与存储过程相关的搜索框。这是我所做的唯一重大更改,但不确定为什么会产生任何影响。
我确实删除了我添加的搜索框,但这并没有改变任何东西。我将按钮上的自动回发更改为 false,这也没有改变任何东西。我已经删除了数据绑定,重新添加了它们,似乎没有任何东西可以让按钮工作。
这里是“删除喜欢”按钮。由于“删除不喜欢”按钮是相同的,我不会粘贴该代码。
Protected Sub RemoveLikeBtn_Click(sender As Object, e As EventArgs) Handles RemoveLikeBtn.Click
Dim connection As New SqlConnection(My.Settings.dbInterests)
Dim insertProcedure As String = "sp_Delete_ClientInterests"
Dim insertCommand As New SqlCommand(insertProcedure, connection)
insertCommand.CommandType = CommandType.StoredProcedure
insertCommand.Parameters.AddWithValue("@ClientInterestID", LikesLB.SelectedValue)
Try
connection.Open()
insertCommand.ExecuteNonQuery()
Catch ex As SqlException
MsgBox("Please select an interest to remove")
Finally
connection.Close()
End Try
LikesLB.DataBind()
InterestsLB.DataBind()
DislikesLB.DataBind()
这是存储过程
CREATE PROCEDURE [dbo].[sp_Delete_ClientInterests]
(@ClientInterestID INT)
AS
DELETE FROM ClientInterests
WHERE ID = @ClientInterestID;
GO
这里是它所绑定的列表框,以及按钮控件本身
<div class="col-md-3 bgLightgreen">
<h5>Individual Likes</h5>
<telerik:RadListBox ID="LikesLB" runat="server" Height="500px" Width="100%" Sort="Ascending" DataSourceID="dboInterestLikeList" DataTextField="Interest" DataValueField="InterestID" Skin="MetroTouch">
<ButtonSettings TransferButtons="All"></ButtonSettings>
</telerik:RadListBox>
<asp:SqlDataSource ID="dboInterestLikeList" runat="server" ConnectionString="<%$ ConnectionStrings:Interests.My.MySettings.dbInterests %>" SelectCommand="sp_Client_Interest_Likes_List" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ClientDDL" Name="ClientID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<telerik:RadButton ID="RemoveLikeBtn" runat="server" Text="Remove a Like" BackColor="#CCCCCC"></telerik:RadButton>
</div>
【问题讨论】:
-
您对 proc 没有运行的确定性如何?也许它只是没有找到要删除的内容,或者传入的参数值不正确。
-
或者您正在使用 AttachDbFileName 并且实际上没有检查数据库的正确副本...显示完整的连接字符串(当然减去任何密码)。
-
旁注:您应该不为您的存储过程使用
sp_前缀。微软有reserved that prefix for its own use (see Naming Stored Procedures),你确实会在未来某个时候冒着名称冲突的风险。 It's also bad for your stored procedure performance。最好只是简单地避免sp_并使用其他东西作为前缀 - 或者根本不使用前缀! -
如果使用SSMS,您可以监控数据库事务:在工具下,单击SQL Server Profiler,连接到服务器,在“使用模板”下选择“TSQL_SPs”,选择“事件选择”选项卡,单击“列过滤器”,单击“DatabaseName”,展开“Like”节点,输入您的数据库名称,单击“确定”,然后单击“运行”。使用顶部的暂停和播放按钮来控制分析器何时收听。启动它,测试您的按钮,然后暂停它,并查看日志以查看 SQL 是否通过并准确查看传入了哪些值。
-
sp_ 正是我的上司教给我的。我刚刚遵循了相同的命名程序。
标签: sql-server vb.net stored-procedures