Re: How do i change my code to use storedprocedure to select data RRS feed

  • Question

  • User-2074858223 posted

    Am having error on this line of code, the error is the name CommanType does not exist in the current context, 


     MYPOST does not exist in the current context

    cmd.CommandText = MYPOST; //this should be the name of the stored procedure which is MYPOST and not a SELECT query
    	cmd.CommandType = CommmandType.StoredProcedue;

    return dt; (ERROR- Can not leave the body of a final clause)

    Sunday, November 8, 2015 11:37 PM


  • User1884398186 posted

    There was a missing parenthesis in my original code, which I have corrected.  You can get the latest code. Also note the below points.

    • Pass a string like "MyPost" to the method I have in my first answer i.e. enclosed within double quotes.
    • Make sure that you have a stored procedure by that name in the database else you will get another error.

    Call the method as shown below and make sure that the id value is also a string representing some id in the database.

     ConnectDataBaseReturnDT("MYPOST", id);

    When using stored procedure name always enclose the name of stored in quotes as below.

    cmd.CommandText = "MYPOST";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 9, 2015 12:33 AM