Cannot insert row in a datatable from sqldatareader

This is the error that I am getting:

"An exception of type 'System.InvalidCastException' occurred in System.Data.dll but was not handled in user code"

This is my code. The error is pointing at the line where I am adding a row. I already searched the net and it said that there should be no null values in the database, so I changed the contents but it still produces the same error.

protected DataTable getIncidentResponseByPriority(int priority) { sqlt = "SELECT tto_received,tto_met,tto_missed,tto_percentage,tto_breach_reason FROM handover_incidentresponse WHERE modified_at =(SELECT MAX(modified_at) FROM handover_incidentresponse) and priority [email protected] ORDER BY incident_response_id DESC;"; SqlCommand cmd = new SqlCommand(sqlt, con); cmd.Parameters.AddWithValue("@priority", priority); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); String pri; if (priority == 1) pri = "1 - Top"; else if (priority == 2) pri = "2 - High"; else if (priority == 3) pri = "3 - Medium"; else pri = "4 - Low"; DataTable dt = new DataTable(); if (reader.HasRows) { while (reader.Read()) { dt.Rows.Add(pri, reader.GetInt64(0), reader.GetInt64(1), reader.GetInt64(2), reader.GetInt64(3), "3 hours", " > 70%", " > 80%", reader.GetTextReader(4));> error is in this line } } con.Close(); return dt; }

Category:c# Views:0 Time:2018-10-07

Related post

Copyright (C), All Rights Reserved.

processed in 0.124 (s). 11 q(s)