我正在尝试从Gridview中删除一条记录,并且收到一条InvalidCastException,消息为“从字符串“ RefYear”转换为'Integer'类型无效。我也在使用数据键。
相关列的Gridview代码部分
<asp:TemplateField HeaderText="Ref. Year" SortExpression="ReferenceYear" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RefYear") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("RefYear") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="btnInsertRecord" runat="server" CommandName="Insert" Text="Insert Record"
ValidationGroup="Insert" CssClass="buttonBlue" />
</FooterTemplate>
</asp:TemplateField>
隐藏代码
Protected Friend Sub dgvBusinessCompetitions_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles dgvBusinessCompetitions.RowDeleting
' Read the keys from data keys
Dim _rewardDescription As String = dgvBusinessCompetitions.DataKeys(e.RowIndex)("RewardDescription")
Dim _referenceYear As Integer = dgvBusinessCompetitions.DataKeyNames(1)
Eurolife.Applications.ProductionEngine.BusinessAccess.BusinessCompetitionBusinessAccess.DeleteBusinessCompetitionReward(_rewardDescription,
_referenceYear,
_groupType)
InformationBox.ShowSuccessMessage("Record deleted successfully.")
loadBusinessCompetitionsConditions()
End Sub
存储过程
ALTER PROCEDURE [dbo].[my_procedure]
@rewardDescription VARCHAR(100),
@groupType VARCHAR (50),
@refYear INT
AS
BEGIN
DELETE FROM myTable
WHERE RewardDescription = @rewardDescription
AND GroupType = @groupType
AND RefYear = @refYear
END
我需要做的是,单击删除后,我需要在存储过程显示时删除带有X奖励说明,X组类型和X RefYear的特定记录。
我尝试过转换RefYear,但是没有用。
有什么想法吗?
答案 0 :(得分:1)
已更改
Dim _referenceYear As Integer = dgvBusinessCompetitions.DataKeyNames(1)
收件人
Dim _referenceYear As Integer = dgvBusinessCompetitions.DataKeys(e.RowIndex)("RefYear")