【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 ...
随机推荐
- 行星万象表白墙微信小程序、社交微信小程序,后台完整,支持多区域运营,扫码体验。
简介 中国目前大概有5000个表白墙,累计用户近3000万,是一个庞大的群体,但现在大都以微信朋友圈为基础进行信息中转,但是这种模式经营者和用户都不友好,尤其是经营者无法变现,用户无法公开评论,这些种 ...
- [atARC064F]Rotated Palindromes
(长度为$n$的序列$a_{i}$,下标范围为$[0,n)$,且用字符串的方式即$a_{[l,r]}$来表示子区间) 定义一个长为$n$的序列$a_{i}$的周期为的$l$满足$l|n$且$\fora ...
- [bzoj3317]First Knight
建立方程后直接高斯消元,再把0的区间找出来计算,就可以过(因为实际上这样的复杂度是5次的,且常数小)(当然这样的复杂度看上去并不太好,考虑优化)可以发现最后一行的概率都可以用上一行来表示,那么代入上一 ...
- 手写HashMap,快手面试官直呼内行!
手写HashMap?这么狠,面试都卷到这种程度了? 第一次见到这个面试题,是在某个不方便透露姓名的Offer收割机大佬的文章: 这--我当时就麻了,我们都知道HashMap的数据结构是数组+链表+红黑 ...
- HTML四种定位-固定定位
固定定位 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset=&q ...
- MYSQL免安装
MYSQL免安装 本文使用mysql 8.0.22进行演示 一.MYSQL 下载 [x] 官网下载:地址:https://dev.mysql.com/downloads/mysql/ [x] 百度云盘 ...
- Go IF 条件语句
条件语句需要开发者通过指定一个或多个条件,并通过测试条件是否为 true 来决定是否执行指定语句,并在条件为 false 的情况在执行另外的语句. 以下是在大多数编程语言中发现的典型条件语句的一般形式 ...
- JS设计模式之建造者模式
建造者模式(builder pattern)属于创建型模式的一种,提供一种创建复杂对象的方式.它将一个复杂的对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 建造者模式是一步一步的创建 ...
- MicrosoftPowerBI—2019-nCov 新型冠状病毒肺炎多功能动态看板
https://app.powerbi.cn/view?r=eyJrIjoiNmE0ZDU0MGItOTFjYy00MWYyLWFmZjMtMThkM2EwMzg5YjgyIiwidCI6ImQxNj ...
- zabbix-磁盘状态脚本
#/bin/sh Device=$1 DISK=$2 case $DISK in tps) iostat -dmt 1 2|grep "\b$Device\b"|tail -1|a ...
