I am trying to GET all values from a Oracle Table using a web api.
The Get works fine when there are no null values for columns in oracle table
but returns a http 500 when any of the columns are null in the table. Is there a way to handle this without using a procedure? Below is the method I am using would like to keep the logic same if possible. Any suggestions are appreciated.
[HttpGet]
[ActionName("GetData")]
public object Get()
{
List<SelectData> TestList = new List<SelectData>();
string connStr = ConfigurationManager.AppSettings.Get("ConnStr");
using (var conn = new OracleConnection(connStr))
{
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "select * from DB_DATA";
cmd.Connection = conn;
OracleDataReader dr = cmd.ExecuteReader();
SelectData ListObject = new SelectData();
while (dr.Read())
{
//Error if any of these are null
ListObject.DATA_ID = dr.GetInt32(0);
ListObject.Name = dr.GetString(1);
ListObject.LastName = dr.GetString(2);
ListObject.COMMENTS = dr.GetString(3);
ListObject.Address = dr.GetString(4);
TestList.Add(ListObject);
}
conn.Close();
}
return TestList;
}