从对象类型System.Web.UI.WebControls.Label到已知的托管提供程序本机类型不存在映射

时间:2016-08-19 05:54:42

标签: c# asp.net gridview

iam尝试将gridview标签作为参数在sql中根据该标签进行更新但是它显示错误,因为从对象类型System.Web.UI.WebControls.Label到已知的托管提供者本机类型存在No mapping。请帮我提前谢谢以下是我的代码

protected void btnSave_Click(object sender, EventArgs e)
{

    using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStrCCUKYC"].ToString()))
    {

        foreach (GridViewRow row in ShowGrid.Rows)
        {


            var Clientid = row.Cells[5].FindControl("lblClientid");

           // var Clientid = row.Cells[5].Text;  Clientid is coming Null 

            //Label Clientid = ((Label)row.FindControl("lblClientid")); No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type.

            CheckBox ckb = (CheckBox)row.FindControl("chkSelect");
            //ckb.Checked = ((CheckBox)sender).Checked;

            if (ckb.Checked==true)
            {

                var check = true;

                SqlCommand cmd = new SqlCommand("sp_InsertRecieved_HOSignaturecard ", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Check", check);
                cmd.Parameters.AddWithValue("@Clientid", Clientid);
                con.Open();
                var res = cmd.ExecuteNonQuery();
                con.Close();
                if (res > 0)
                {

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data Saved successfully..!')", true);
                }

                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data NotSaved..!')", true);
                }


            }

            else
            {

                var check = false;

                SqlCommand cmd = new SqlCommand("sp_InsertRecieved_HOSignaturecard ", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Check", check);
                cmd.Parameters.AddWithValue("@Clientid", Clientid);
                con.Open();
                var res = cmd.ExecuteNonQuery();
                con.Close();
                if (res > 0)
                {

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data Saved successfully..!')", true);
                }

                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data NotSaved..!')", true);
                }   

            }

        }

    }


}

3 个答案:

答案 0 :(得分:1)

protected String doInBackground(String... params) {
    RestClient client = new RestClient(params[0]);

    client.AddParam("username", params[1]);
    client.AddParam("password", params[2]);

    ...
}

上面的代码示例假定您的ASPX标记已正确完成。如果您仍然无法获得正确的价值,请在您的问题中提供您的ASPX代码。

<强>更新

  

对于UPDATE,INSERT和DELETE语句,返回值为   受命令影响的行数。当a上存在触发器时   正在插入或更新的表,返回值包括数字   受插入或更新操作影响的行数和数字   受触发器或触发器影响的行数。对于所有其他类型的   语句,返回值为-1。如果发生回滚,则返回   值也是-1。

如果您的var lblClientid = row.cells[5].Controls[0].FindControl("lblClientid") as Label; if (lblClientid != null) { // do something if found the control... // e.g. assign the value to a variable var ClientId = lblClientid.Text; } 返回-1,则需要检查存储过程并查看选项cmd.ExecuteNonQuery()是否开启/关闭。

有关详细信息,请查看https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx

答案 1 :(得分:0)

您必须在参数中使用ClientId.Text,而不是ClientId

答案 2 :(得分:0)

我已经得到答案他们在阅读网格值时没有错,但错误就在附近

var check = true;

它应该是 var check =“true”;

感谢 woodykiddy 提供答案。