I have a Web API which returns a datatable
public async Task<IHttpActionResult> SelectExtension(DateTime start, DateTime end, string institution)
{
var identity = (ClaimsIdentity)User.Identity;
var facility= claimIdentity.GetIdentityValue("Institution", identity).First();
DataTable table = new DataTable("Result");
var cmd = new SqlCommand();
using (SqlConnection con = connection.DB())
{
try
{
con.Open();
var query = generalData.SelectExtension(start, end, facility, institution);
cmd = command.CreateQuery(query.Query, query.ProcdureParameters, con);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd);
sqlDataAdapter.Fill(table);
}
catch (Exception e)
{
var error = $"Code: {e.HResult}\n Message: {e.Message}\n InnerException: {e.InnerException}\n Stack: {e.StackTrace}";
await stream.WriteAsync(error);
return InternalServerError();
}
}
return Ok(table);
}
which has a column with a datatype of DateTime
table.Rows[6]["ApprovedExtendedEndDate"]
{11/25/2021 12:00:00 AM}
Date: {11/25/2021 12:00:00 AM}
Day: 25
DayOfWeek: Thursday
DayOfYear: 329
Hour: 0
Kind: Unspecified
Millisecond: 0
Minute: 0
Month: 11
Second: 0
Ticks: 637733952000000000
TimeOfDay: {00:00:00}
Year: 2021
When this is return to the client the datatype of the column is changed to string
Http Client Code
public async Task<DataTable> SelectExtension(DateTime start, DateTime end, string institution)
{
try
{
var response = await ClientHttp.HttpClient.Client.GetAsync($"{controller}/SelectExtension/{start:yyyy-MM-dd}/{end:yyyy-MM-dd}/{institution}");
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsAsync<DataTable>();
return result;
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
{
FormAction.Alert("You do not have permission to access this resource", FormAction.enmType.Error);
return null;
}
return null;
}
The value in the column now becomes a string
result.Rows[6]["ApprovedExtendedEndDate"]
"11/25/2021 00:00:00"
Can anyone please help me to identify why it is not able to convert it to a dateTime.
It is not the only datetime column in the datatable but this particular one is return a string.