From 188cb047eae43e067560006239af14ee66272dba Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 10 May 2016 09:14:10 -0700 Subject: [PATCH] Try-catch is the best solution, since people might be using a blank dats.sqlite instead of the prepopulated one --- DATabaseTwo/Import.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/DATabaseTwo/Import.cs b/DATabaseTwo/Import.cs index 4b7c94fb..552b5f77 100644 --- a/DATabaseTwo/Import.cs +++ b/DATabaseTwo/Import.cs @@ -128,7 +128,7 @@ COMMIT;"; string source = GetSourceFromFileName(Path.GetFileName(file)); int sourceid = 0; - Dictionary sources = new Dictionary(); + SortedDictionary sources = new SortedDictionary(); sources.Add("default", 0); query = "SELECT name, id FROM source"; using (SqliteCommand sslc = new SqliteCommand(query, dbc)) @@ -208,13 +208,27 @@ COMMIT;"; // Otherwise, get the ID else if (source != "" && sourceid == 0 && sources.ContainsKey(source)) { - sourceid = sources[source.ToLowerInvariant()]; + try + { + sourceid = sources[source.ToLowerInvariant()]; + } + catch + { + sourceid = 0; + } } // Otherwise, we should already have an ID } else { - sourceid = sources[source.ToLowerInvariant()]; + try + { + sourceid = sources[source.ToLowerInvariant()]; + } + catch + { + sourceid = 0; + } } // Add the source and system link to the database