【编程语言】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.问题解决

【C#】【MySQL】【GridView】删除出现Parameter index is out of range的更多相关文章

  1. [转]操作MySQL数据库报出:Parameter index out of range (1 > number of parameters, which is

    原文地址:https://blog.csdn.net/zdx_y/article/details/52072914 对MySQL进行insert操作,控制台抛出以下错误:Parameter index ...

  2. .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"的问题

    在.NET中使用GridView控件的在线编辑数据时,出现了“ Index was out of range. Must be non-negative and less than the size ...

  3. MySql.Data.MySqlClient.MySqlException: Parameter ‘@maxid’ must be defined

    本文涉及到的mysql知识点: mysql中的if条件语句用法: IF(expr1,expr2,expr3) mysql使用变量(mysql中变量不用事前申明) mysql事务 testcase 为了 ...

  4. mysql优化, 删除数据后物理空间未释放(转载)

    mysql优化, 删除数据后物理空间未释放(转载) OPTIMIZE TABLE 当您的库中删除了大量的数据后,您可能会发现数据文件尺寸并没有减小.这是因为删除操作后在数据文件中留下碎片所致.OPTI ...

  5. mySQL中删除unique key的语法 (删除某个字段的唯一性)

    mySQL中删除unique key的语法 CREATE TABLE `good_booked` (  `auto_id` int(10) NOT NULL auto_increment,  `goo ...

  6. Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0

    1.错误描述 [ERROR:]2015-05-05 16:35:50,664 [异常拦截] org.hibernate.exception.GenericJDBCException: error ex ...

  7. mybatis中Parameter index out of range (1 > number of parameters, which is 0).

    Parameter index out of range (1 > number of parameters, which is 0).(参数索引超出范围) 在mybatis里面写就是应该是 l ...

  8. java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).

    java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2). java. ...

  9. java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

    java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at co ...

随机推荐

  1. 8大原则带你秒懂Happens-Before原则

    摘要:在并发编程中,Happens-Before原则是我们必须要掌握的,今天我们就一起来详细聊聊并发编程中的Happens-Before原则. 本文分享自华为云社区<[高并发]一文秒懂Happe ...

  2. MySQL基础语句(修改)

    ①INSERT INSERT INTO students (class_id, name, gender, score) VALUES (2, '大牛', 'M', 80); 向students表插入 ...

  3. Django 小实例S1 简易学生选课管理系统 3 创建用户模型(model)

    Django 小实例S1 简易学生选课管理系统 第3节--创建用户模型(model) 点击查看教程总目录 作者自我介绍:b站小UP主,时常直播编程+红警三,python1对1辅导老师. 本文涉及到的新 ...

  4. [luogu6466]分散层叠算法

    做法1 对于每一个询问,直接暴力在每一个序列中二分查询 时间复杂度为$o(nk)-o(k\log n)$ 做法2 将所有序列合并后排序,并对每一个元素预处理出每个序列中第一个大于等于其的元素(位置), ...

  5. [loj3367]装饼干

    先考虑如何判定一个$y$是否可行--从高位开始,记录这一位所需要的$2^{i}$数量$t$,若$y$的这一位为1,则$t+=x$,之后分两类讨论:1.$t\le a_{i}$,令$t=0$:2.$b& ...

  6. LOJ 3399 -「2020-2021 集训队作业」Communication Network(推式子+组合意义+树形 DP)

    题面传送门 一道推式子题. 首先列出柿子,\(ans=\sum\limits_{T_2}|T_1\cap T_2|·2^{T_1\cap T_2}\) 这个东西没法直接处理,不过注意到有一个柿子 \( ...

  7. map与unordered_map区别及使用

    需要引入的头文件不同map: #include <map>unordered_map: #include <unordered_map> 内部实现机理不同map: map内部实 ...

  8. 【R】一对一变为一对多:将列折叠/连接/聚合为每个组(一行)内的字符串?

    目录 需求 实现 方法一 其他方法 data.table dplyr aggregate sqldf 延申:不用逗号分隔 需求 原始文件: data <- data.frame(A = c(re ...

  9. Redis队列跟MQ的区别

    Redis队列:Redis队列是一个Key-Value的NoSQL数据库,开发维护很活跃,虽然是一个Key-Value数据库存储系统,但它本身支持MQ功能,所以完全可以当做一个轻量级的队列服务来使用 ...

  10. 【转】NG:垂枝桦基因组图谱构建(2+3组装)及重测序分析

    转自希望组公众号.学习二代+三代组装策略的流程 垂枝桦(Betula pendula)是一种速生乔木,能在短短一年时间内开花,木质坚实,可做细工.家具等,经济价值极高.近日,芬兰研究人员对垂枝桦自交系 ...