【编程语言】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. C#窗体学习

    //进度条控件 private void button1_Click(object sender, EventArgs e)        {            int i;            ...

  2. [cf1184E]Daleks' Invasion

    先求出任意一棵最小生成树,然后对边分类讨论1.非树边,答案即最小生成树的环上的最长边2.树边,反过来考虑,相当于对于每一个点对那条路经打上标记,取min对于1直接用倍增维护即可,对于2可以用树链剖分/ ...

  3. [loj4]Quine

    很有趣的一道题目,如何让一个程序输出自身如果用字符串s表示程序,那么意味着可以通过s来输出sprintf是一个可以利用的函数,相当于要求printf(s,s)输出的就是s那么只需要在s中加入%c和%d ...

  4. ML2021 | (腾讯)PatrickStar:通过基于块的内存管理实现预训练模型的并行训练

    ​  前言  目前比较常见的并行训练是数据并行,这是基于模型能够在一个GPU上存储的前提,而当这个前提无法满足时,则需要将模型放在多个GPU上.现有的一些模型并行方案仍存在许多问题,本文提出了一种名为 ...

  5. mybatis新增账号并且返回主键id

    <!--新增账号和权限的关联关系--><insert id="save" useGeneratedKeys="true" keyPropert ...

  6. 7.1 k8s使用configmapg 给pod内的程序提供配置文件

    ConfigMap 是一种 API 对象,用来将非机密性的数据保存到键值对中.使用时, Pods 可以将其用作环境变量.命令行参数或者存储卷中的配置文件. 以下以nginx镜像提供配置文件为例镜像演示 ...

  7. Codeforces 1455G - Forbidden Value(map 启发式合并+DP)

    Codeforces 题面传送门 & 洛谷题面传送门 首先这个 if 与 end 配对的结构显然形成一个树形结构,考虑把这棵树建出来,于是这个程序的结构就变为,对树进行一遍 DFS,到达某个节 ...

  8. 洛谷 P3214 - [HNOI2011]卡农(线性 dp)

    洛谷题面传送门 又是一道我不会的代码超短的题( 一开始想着用生成函数搞,结果怎么都搞不粗来/ll 首先不妨假设音阶之间存在顺序关系,最终答案除以 \(m!\) 即可. 本题个人认为一个比较亮的地方在于 ...

  9. Codeforces 1264F - Beautiful Fibonacci Problem(猜结论+找性质)

    Codeforces 题面传送门 & 洛谷题面传送门 一道名副其实(beautiful)的结论题. 首先看到这道设问方式我们可以很自然地想到套用斐波那契数列的恒等式,注意到这里涉及到 \(F_ ...

  10. 洛谷 P6860 - 象棋与马(找性质+杜教筛)

    题面传送门 首先我们来探究一下什么样的 \((a,b)\) 满足 \(p(a,b)=1\).不难发现只要点 \((1,0)\) 能够到达,那么网格上所有点都能到达,因为由于 \((1,0)\) 能够到 ...