Fix SqlNullValueException

This commit is contained in:
frauseo 2020-05-26 21:18:56 +02:00
parent cd162d1ee6
commit 43aa400613
2 changed files with 24 additions and 16 deletions

View File

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2622C2FC-3522-4D6F-B021-F63A243E77F1}</ProjectGuid> <ProjectGuid>{2622C2FC-3522-4D6F-B021-F63A243E77F1}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>LoggingClient</RootNamespace> <RootNamespace>LoggingClient</RootNamespace>
<AssemblyName>LoggingClient</AssemblyName> <AssemblyName>LoggingClient</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>

View File

@ -145,10 +145,16 @@ namespace LoggingClient.ViewModel
var reader = cmd.ExecuteReader(); var reader = cmd.ExecuteReader();
while (reader.Read()) while (reader.Read())
{ {
// ISDBNull Check because location can be NULL in Database
var location = "";
if (!reader.IsDBNull(reader.GetOrdinal("location")))
{
location = reader.GetString("location");
}
Logs.Add(new LogModel( Logs.Add(new LogModel(
reader.GetInt32("id"), reader.GetInt32("id"),
reader.GetString("pod"), reader.GetString("pod"),
reader.GetString("location"), location,
reader.GetString("hostname"), reader.GetString("hostname"),
reader.GetInt32("severity"), reader.GetInt32("severity"),
reader.GetDateTime("timestamp"), reader.GetDateTime("timestamp"),
@ -156,14 +162,16 @@ namespace LoggingClient.ViewModel
)); ));
} }
} }
conn.Close();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
//MessageBox.Show("Error occurred: " + ex.Message); MessageBox.Show("Error occurred: " + ex.Message);
} }
} }
private void BtnLogClear_Click() private void BtnLogClear_Click()
{ {
if (MySelectedItem == null) return; if (MySelectedItem == null) return;