Cis Pa

Cis Pa

  • NA
  • 194
  • 22.9k

Restwebapi list and store into Dataset in client application

Jun 7 2021 4:10 AM

Hi all

Created  Enumerable list in RESTAPI to get the student list based on schoolid and its working in Fiddler.i was tring to consum the list into client windows application to store the datas into Dataset but its shows empty.Please help

WEB api

 public IEnumerable<student> Getstudent(string schoolId)
        {
                 SqlDataAdapter da = new SqlDataAdapter("Getstudent", con);
                DataTable ds = new DataTable();
                con.Open();
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter ret = new SqlParameter();
                ret.Direction = ParameterDirection.ReturnValue;
                da.SelectCommand.Parameters.Add("@schoolId", SqlDbType.VarChar, 20).Value = schoolId;
                da.SelectCommand.Parameters.Add(ret);
                da.Fill(ds);
                var result = (from rw in ds.Select()
                              select new schoollist
                              {
                                  ID = Convert.ToString(rw["ID"]),
                                  Name = Convert.ToString(rw["Name"]),
                                  SchoolName =Convert.ToString(rw["SchoolName"]),
                              }).ToList();
                return result;

}

 

client application

             HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = await client.GetAsync(builder.Uri);
            string result = await response.Content.ReadAsStringAsync();


Answers (1)