locked
Error - No mapping exists from object type System.Web.UI.WebControls.HiddenField to a known managed provider native type. RRS feed

  • Question

  • User-1499457942 posted

    Hi

      When i try to Delete record i get above error

    protected void lnkBtnDelete_Click(object sender, EventArgs e)
            {
                try
                {
                    using (SqlConnection con = new SqlConnection(CommonFunction.connectionString))
                    {
                        LinkButton lnkbtn = sender as LinkButton;
                        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
                        HiddenField hdf_No = (gvrow.FindControl("hdfNo") as HiddenField);
    
                        SqlCommand cmd = new SqlCommand("Sp_Inflator", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Action", "D");
                        cmd.Parameters.AddWithValue("@No", hdf_No);
                        con.Open();
                        cmd.ExecuteNonQuery();
                        string message = CommonFunction.recordDeletedSucessfully;
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
                    }
                }
                catch (Exception ex)
                {
                    //ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + ex.Message + "');", true);
                }
            }
    
    
    USE [Test]
    GO
    
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:		<Author,,Name>
    -- Create date: <Create Date,,>
    -- Description:	<Description,,>
    -- =============================================
    ALTER PROCEDURE [dbo].[sp_Test]
          @Action VARCHAR(1)
    	  ,@No int = Null
          ,@Code VARCHAR(10) = NULL
    	  ,@Status VARCHAR(1) = Null
    AS
    BEGIN
          SET NOCOUNT ON;
     
          --SELECT
    
     
          --DELETE
          IF @Action = 'D'
          BEGIN
                DELETE FROM dbo.Inf WHERE No = @No
          END
    
    END

    Thanks

    Sunday, August 19, 2018 1:21 PM

Answers

  • User475983607 posted

    You've had this same error several time now.  It's absolutely baffling why you keep making the same mistakes over and over.  Maybe you need to slow down a bit and review your code rather than posted every time you have an error.

    Anyway, this code is trying to send the entire hidden server control to the the SQL script.

    cmd.Parameters.AddWithValue("@No", hdf_No);
    

    Pass the value

    cmd.Parameters.AddWithValue("@No", hdf_No.Value);
    

    Actually what you should do is verify the hidden field value before mindlessly jamming it into the SQL script. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 19, 2018 1:44 PM