【C#】【MySQL】【GridView】删除出现Parameter index is out of range

【编程语言】C#

【数据库】MySQL

【控件】GridView

【问题描述】GridView控件中自带[删除],[编辑],[选择],三个按钮[编辑],[选择]正常使用,但是在使用删除时,却报错Parameter index is out of range

报错页面截图如下:报错页面

【代码】

aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="icode.aspx.cs" Inherits="WebApplication_OmtpcMgrSystem.admin.icode" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
        <form id="form1" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:omtpcConnectionString %>" DeleteCommand="DELETE FROM invitationcode WHERE 注册码 = ?" InsertCommand="INSERT INTO invitationcode (创建日期, 注册码, 可用次数, 使用日期, 使用用户) VALUES (?, ?, ?, ?, ?)" ProviderName="<%$ ConnectionStrings:omtpcConnectionString.ProviderName %>" SelectCommand="SELECT * FROM invitationcode" UpdateCommand="UPDATE invitationcode SET 创建日期 = ?, 可用次数 = ?, 使用日期 = ?, 使用用户 = ? WHERE 注册码 = ?">
        <DeleteParameters>
            <asp:Parameter Name="注册码" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="创建日期" Type="DateTime" />
            <asp:Parameter Name="注册码" Type="String" />
            <asp:Parameter Name="可用次数" Type="String" />
            <asp:Parameter Name="使用日期" Type="DateTime" />
            <asp:Parameter Name="使用用户" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="创建日期" Type="DateTime" />
            <asp:Parameter Name="可用次数" Type="String" />
            <asp:Parameter Name="使用日期" Type="DateTime" />
            <asp:Parameter Name="使用用户" Type="String" />
            <asp:Parameter Name="注册码" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
        </Columns>
    </asp:GridView>
        </form>
</body>
</html>
aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication_OmtpcMgrSystem.admin
{
    public partial class WebForm_CreateCode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

已确认配置文件齐全,MySQL命令无误,C#代码无误

【解决方案】

1.选中控件

例图

2.找到控件属性[DataKeyNames]

例图

3.将主键名填入进入

例如:我的主键名是注册码,那么,我就在这个地方填写 注册码例图

4.问题解决

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萌狼蓝天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值