c# - 在 GridView 中进行删除操作时出错
问题描述
这是我的网格视图删除操作的代码,使用storedprocedure
. 我收到此错误:{"No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type."}
protected void GVEmployee_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = GVEmployee.Rows[e.RowIndex];
Control c1 = row.FindControl("Label1");
Label l1 = (Label)c1;
SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBCM"].ConnectionString;
SqlCommand cmd = new SqlCommand("delete from Spempdet where Id= ' " + ID , con);
con.Open();
cmd.Parameters.AddWithValue("@Id", l1);
cmd.ExecuteNonQuery();
con.Close();
Bind();
}
解决方案
据我所知,您需要在“”中传递值,因此您的 SQL 命令应该如下所示
SqlCommand cmd = new SqlCommand("delete from Spempdet where Id= ' " + ID+" ' " , con);
推荐阅读
- excel - 做 While 循环,但只返回第一个指定的值
- java - Powershell 卸载 java 32 和 64 位
- dynamic - 我怎样才能通过字典
到 Blazor 组件? - google-cloud-platform - Dataprep - 架构与每次计划运行的配方都不匹配
- amazon-web-services - 将 Kubernetes 应用程序从 AWS 迁移到 GCP
- flutter - Flutter 验证器语法错误
- r - 在 R 中的几个 data.frame 对象中更改单个列名
- java - Evosuite 1.0.6 - 如何设置外部依赖库
- python - 如何使用 (python3) help() 查找参数定义
- python - xlsxwriter y2 轴格式不正确