Fix SqlNullValueException
This commit is contained in:
parent
cd162d1ee6
commit
43aa400613
@ -5,7 +5,7 @@
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2622C2FC-3522-4D6F-B021-F63A243E77F1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>LoggingClient</RootNamespace>
|
||||
<AssemblyName>LoggingClient</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
|
@ -10,7 +10,7 @@ using LoggingClient.ViewModel.Commands;
|
||||
|
||||
namespace LoggingClient.ViewModel
|
||||
{
|
||||
public class LogViewModel : INotifyPropertyChanged
|
||||
public class LogViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _txtConnectionString;
|
||||
private string _enterPod;
|
||||
@ -142,28 +142,36 @@ namespace LoggingClient.ViewModel
|
||||
conn.Open();
|
||||
using (var cmd = new MySqlCommand("SELECT id, pod, location, hostname, severity, timestamp, message FROM v_logentries ORDER BY timestamp", conn))
|
||||
{
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
Logs.Add(new LogModel(
|
||||
reader.GetInt32("id"),
|
||||
reader.GetString("pod"),
|
||||
reader.GetString("location"),
|
||||
reader.GetString("hostname"),
|
||||
reader.GetInt32("severity"),
|
||||
reader.GetDateTime("timestamp"),
|
||||
reader.GetString("message")
|
||||
));
|
||||
var reader = cmd.ExecuteReader();
|
||||
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(
|
||||
reader.GetInt32("id"),
|
||||
reader.GetString("pod"),
|
||||
location,
|
||||
reader.GetString("hostname"),
|
||||
reader.GetInt32("severity"),
|
||||
reader.GetDateTime("timestamp"),
|
||||
reader.GetString("message")
|
||||
));
|
||||
}
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//MessageBox.Show("Error occurred: " + ex.Message);
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnLogClear_Click()
|
||||
{
|
||||
if (MySelectedItem == null) return;
|
||||
|
Loading…
Reference in New Issue
Block a user