首页 > 解决方案 > 在 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();
}

标签: c#asp.net

解决方案


据我所知,您需要在“”中传递值,因此您的 SQL 命令应该如下所示

SqlCommand cmd = new SqlCommand("delete from Spempdet where Id= ' " + ID+" ' " , con);

推荐阅读