none
Procedure or function 'sp_' expects parameter '@FormName', which was not supplied."} RRS feed

  • Question

  • I'm not sure what I did wrong here or missing rather. I have tried this a few ways. Still giving me an error

    public string GetGUI_FormDisplayInformation(string FormName)
            {
                try
                {
                    SqlConnection SQLConn = new SqlConnection(cn);
                    SqlCommand cmd = new SqlCommand("sp_SELECT_GUI_Form_Display_Information", SQLConn);
                    string str;
    
                    cmd.Parameters.AddWithValue("@FormName", FormName);
    
                    //cmd.Parameters.Add(new SqlParameter("@FormName", SqlDbType.NVarChar, 150));
                    //cmd.Parameters["@FormName"].Value = FormName;
    
    
                    SQLConn.Open();
                    str = Convert.ToString(cmd.ExecuteNonQuery());
                    SQLConn.Close();
    
                    return str;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }

    Tuesday, March 13, 2018 8:31 PM

Answers

  • Hello,

    First off I don't see you setting CommandType to Stored procedure e,g, CommandType.StoredProceure. See if this makes a differences along with validating the naming is correct for the param to match the one going into AddWithValue.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by old_School Tuesday, March 13, 2018 8:57 PM
    Tuesday, March 13, 2018 8:50 PM
    Moderator
  • thank you 

     SqlConnection SQLConn = new SqlConnection(cn);
                    SqlCommand cmd = new SqlCommand("sp_SELECT_GUI_Form_Display_Information", SQLConn);
                    string str;
    
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@FormName", FormName);
    
                    //cmd.Parameters.Add(new SqlParameter("@FormName", SqlDbType.NVarChar, 150));
                    //cmd.Parameters["@FormName"].Value = FormName;
    
    
                    SQLConn.Open();
                    str = Convert.ToString(cmd.ExecuteNonQuery());
                    SQLConn.Close();
    
                    return str;

    • Marked as answer by old_School Tuesday, March 13, 2018 8:57 PM
    Tuesday, March 13, 2018 8:57 PM

All replies

  • Hello,

    First off I don't see you setting CommandType to Stored procedure e,g, CommandType.StoredProceure. See if this makes a differences along with validating the naming is correct for the param to match the one going into AddWithValue.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by old_School Tuesday, March 13, 2018 8:57 PM
    Tuesday, March 13, 2018 8:50 PM
    Moderator
  • thank you 

     SqlConnection SQLConn = new SqlConnection(cn);
                    SqlCommand cmd = new SqlCommand("sp_SELECT_GUI_Form_Display_Information", SQLConn);
                    string str;
    
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@FormName", FormName);
    
                    //cmd.Parameters.Add(new SqlParameter("@FormName", SqlDbType.NVarChar, 150));
                    //cmd.Parameters["@FormName"].Value = FormName;
    
    
                    SQLConn.Open();
                    str = Convert.ToString(cmd.ExecuteNonQuery());
                    SQLConn.Close();
    
                    return str;

    • Marked as answer by old_School Tuesday, March 13, 2018 8:57 PM
    Tuesday, March 13, 2018 8:57 PM