Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have A desktop Application with c#
I Created An API Called
GetAsync

it Get's me Some Data From Remote Server (Table Name Is TempData)
what I want to do Is To Get My Data Inside New List Of TempData
To Preview It Inside Datagridview
public class TempData
        {
            [Key]
            public int Id { get; set; }
            [Required(ErrorMessage = "Please Fill The Cheque Number Field")]
            public string CheckNumber { get; set; }
            public DateTime? AddedDate { get; set; }
            public DateTime? DueDate { get; set; }
            public string UnitCode { get; set; }
            public int? UnitClientCode { get; set; }
            public int? UnitDBCode { get; set; }
            public string ClientId { get; set; }
            public decimal? InstallmentAmount { get; set; }
            public string CustomerBank { get; set; }
            public string Status { get; set; }
            public int? ContractId { get; set; }
            public string ProjectName { get; set; }
        }

When I Call My API It gives Me An Error:
Cannot Implicitly convert type :"system.collection.Generic.list<tempdata>
to type <tempdata>

can Any One Help Me

What I have tried:

public static async Task<TempData> GetTempData()
        {
            var list = new List<TempData>();
            //DataTable dataTable = new DataTable();
            HttpClient client = new HttpClient();
            HttpResponseMessage responseMessage = await client.GetAsync("http://216.172.100.245:8080/api/TempData");
            if (responseMessage.IsSuccessStatusCode)
            {
                var jstring = await responseMessage.Content.ReadAsStringAsync();
                list = JsonConvert.DeserializeObject<List<TempData>>(jstring);

                //dataTable = JsonConvert.DeserializeObject<DataTable>(jstring);
                return list;
            }
            return list;
        }
Posted
Updated 19-Oct-22 6:05am

1 solution

Just change the return type to List as follows:
public static async Task<list<tempdata>> GetTempData()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900