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


      I have below code . On below line it is giving above error

    String ret = Convert.ToString(cmd.ExecuteScalar());

    protected void ListView_ItemDataBound(object sender, ListViewItemEventArgs e)
                    Label lblCustomerNo = (Label)e.Item.FindControl("lblCustomerNo");
                    Label lblCustomerName = (Label)e.Item.FindControl("lblCustomerName");
                    HiddenField hdfENo = (HiddenField)e.Item.FindControl("hdfENo");
                    SqlCommand cmd;
                    cmd = new SqlCommand("select Left([Status],1) from [tbl_G] where [ENo]=@ENo", con);
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@ENo", hdfENo);
                    String ret = Convert.ToString(cmd.ExecuteScalar());
                catch (Exception ex)


    Saturday, June 30, 2018 10:15 AM


All replies

  • User475983607 posted

    Execute Scalar returns an object.  The convention and recommendations in your other post have this syntax.  There's also reading the openly published documentation.


    string ret = (string)cmd.ExecuteScalar();

    Lastly, are you sure Convert.ToString() is causing the error?  You're hiding exceptions with an empty catch block.  Please take a moment to run your code through the Visual Studio debugger. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 30, 2018 11:20 AM
  • User409696431 posted

    I believe the problem is with this line:

    cmd.Parameters.AddWithValue("@ENo", hdfENo);

    hdfEo is a HiddenField control, not a value.   You should pass the value of the HiddenField, not the HIddenField control itself.

    cmd.Parameters.AddWithValue("@ENo", hdfENo.Value);

    (This assumes you know you'll have a valid value in that HiddenField, otherwise you should validate that first.)

    Sunday, July 1, 2018 1:15 AM