WEB Api: Problem in API (Get) RRS feed

  • Question

  • 1. From Postman

        "Status": 200,
        "Message": "Success.",
        "Data": {
            "Table": [
                    "Slider_ID": 7,
                    "Slider_Name": "Slider 4",
                    "Slider_Img_URL": "Slider/636169083787285383_15055723_10154554079010569_2983182283704857698_n.jpg",
                    "Slider_ID": 9,
                    "Slider_Name": "Slider3",
                    "Slider_Img_URL": "Slider/636023619016433974_3.jpg",

    2. Controller:

            public WebapiOutput GetHomeSlider()
                WebapiOutput result = new WebapiOutput();

                    SliderDAC sliderDAC = new SliderDAC();
                    result.Status = 200;
                    result.Message = "Success.";
                    result.Data =sliderDAC.GetHomeSlider();
                catch (Exception)
                    result.Status = 204;
                    result.Message = "Internal server error.";
                    result.Data = new JObject();
                return result;

    3. Method:

    public DataSet GetHomeSlider()
                    Database objDB = new SqlDatabase(this._sqlConnectionString);
                    DbCommand cmdDB = objDB.GetStoredProcCommand("[dbo].[USP_MMI_GETSLIDER]");

                    var ds = objDB.ExecuteDataSet(cmdDB);
                    return ds;
                catch (Exception)




    public class Slider
            public int Slider_ID { get; set; }

            [Required(ErrorMessage = "Please enter slider name.")]
            public string Slider_Name { get; set; }
            public string Slider_Img_URL { get; set; }

    The Problem is that "Table" is getting printed.

    • Moved by Sabah ShariqMVP Monday, September 4, 2017 1:03 PM Moved From Visual C#
    Monday, September 4, 2017 5:53 AM

All replies

  • Hi there ! 

    It's because you return the dataset , try something like this 

    DataTable firstTable = dataSet.Tables[0];

    loop over the datarows


    Add them to an array of DTO classes (data tranfer object) classes and return the array

    private void PrintRows(DataSet dataSet)
        // For each table in the DataSet, print the row values.
        foreach(DataTable table in dataSet.Tables)
            foreach(DataRow row in table.Rows)
                foreach (DataColumn column in table.Columns)
    //add to an array

    friendly regards


    • Edited by laurens vdb Monday, September 4, 2017 12:36 PM
    Monday, September 4, 2017 6:46 AM
  • A WebAPI is a Web service, and you don't return a dataset or a datatable out of a Web service.


    You should learn how to use a DTO or DTO(s) in a List<T>.




    You should learn how to use a Repository that deals with the CRUD operation with the db and not the Controller.


    WebAPi issues can be dicussed at the forum.


    Monday, September 4, 2017 11:38 AM
  • Hi,

    This is Visual C# forum. As your issue is related to Web, please ask your question into ASP.Net forum for getting quick response. I am moving your thread to off-topic.


    Your understanding and cooperation will be grateful.

    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Monday, September 4, 2017 1:03 PM