【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.问题解决
【C#】【MySQL】【GridView】删除出现Parameter index is out of range的更多相关文章
- [转]操作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 ...
- .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 ...
- MySql.Data.MySqlClient.MySqlException: Parameter ‘@maxid’ must be defined
本文涉及到的mysql知识点: mysql中的if条件语句用法: IF(expr1,expr2,expr3) mysql使用变量(mysql中变量不用事前申明) mysql事务 testcase 为了 ...
- mysql优化, 删除数据后物理空间未释放(转载)
mysql优化, 删除数据后物理空间未释放(转载) OPTIMIZE TABLE 当您的库中删除了大量的数据后,您可能会发现数据文件尺寸并没有减小.这是因为删除操作后在数据文件中留下碎片所致.OPTI ...
- mySQL中删除unique key的语法 (删除某个字段的唯一性)
mySQL中删除unique key的语法 CREATE TABLE `good_booked` ( `auto_id` int(10) NOT NULL auto_increment, `goo ...
- 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 ...
- 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 ...
- 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. ...
- 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 ...
随机推荐
- MyCat读写分离+MySql主从(一主一从)
数据库一直在项目担当着一位核心的角色,是所有项目结构中的底层,说白了,我们程序员进行项目开发都是在和数据打交道,而数据都是保存在数据库中,如mysql.oracle.postgresql等等,如果一个 ...
- vue中this.$set的用法
之前了解这个方法的时候,感觉这一辈子也用不到这个方法,因为当时没有应用场景,但是还真有用的时候,我相信你们也有用到时候. 从三个方面给大家说一下这个this.$set: 1.this.$set实现什么 ...
- QT6 源码杂记
菜鸡一个,随便写写,勿喷.好记性不如烂笔头. 了解qt,第一个绕不过的坎便是qt的元对象系统 QMetaObject. 1 class Object : public QObject 2 { 3 Q_ ...
- jsonpath语法的基本使用
jsonpath的安装及使用方式: pip安装: Python3.7\Scripts> pip install jsonpath jsonpath的使用: obj = json.load(ope ...
- 菜鸡的Java笔记 第二十二 - java 对象多态性
本次只是围绕着多态性的概念来进行讲解,但是所讲解的代码与实际的开发几乎没有关系,而且多态一定是在继承性的基础上才可以操作的, 而本次将使用类继承的关系来描述多态的性质,实际的开发中不会出 ...
- [atAGC106E]Medals
暴力二分答案+网络流,点数为$o(nk)$,无法通过 考虑Hall定理,即有完美匹配当且仅当$\forall S\subseteq V_{left}$,令$S'=\{x|\exists y\in V_ ...
- [nowcoder5667K]Keyboard Free
不妨设$r1\le r2\le r3$,令$f(\alpha)=E(S_{\Delta}ABC)$,其中AB坐标分别为$(r_{1},0)$和$(r_{2}\cos \alpha,r_{2}\sin ...
- NFLSOJ #10317. -「2020联考北附2」三千世界(找等价表达+树形 dp)
题面传送门 出题人可能原本感觉没啥难度的 T2 竟然变成了防 AK 题,奇迹奇迹( 首先带着这个 \(\max\) 肯定不太好处理,考虑找出 \(f(S)\) 的等价表达.我们考虑以 \(1\) 为根 ...
- 洛谷 P7155 [USACO20DEC] Spaceship P(dp)
Portal Yet another 1e9+7 Yet another 计数 dp Yet another 我做不出来的题 考虑合法的按键方式长啥样.假设我们依次按下了 \(p_1,p_2,\dot ...
- python-django-数据查询条件
查询用户的状态是2或者是4的情况 空值和空字符串是不一样的东西!!! 需要注意的是: 项目setting.py里面的时区采用的是美国的时区,我们不要使用这个时区 使用这个时区的,我们输入的日期会进行转 ...
