title: Why does my code make ID null
body: <p>I have a program that gets values from a database through a stored procedure. What it does is gets the values, downloads an image and then uploads it to a server. and after upload the run another stored procedure just to update the table to the new url.</p>
  
  <p>Now it uploads a few images correct then all of a sudden it makes my ID = "" and I cant see why?</p>
  
  <p>Result as log file:</p>
  
  <pre><code>Property ID : 29140
  pk_photo_id (TRY): 47334070
   - File : propimage29140_9.jpg has been uploaded to AWS S3 bucket: ruans
  
  Property ID : 30402
  pk_photo_id (TRY): 47174447
  
  Property ID : 29330
  Property ID :              `&lt;-- why make it nothing`
  pk_photo_id (TRY): 47174392
  ERROR 6 : Cannot insert duplicate key row in object 'dbo.ET_EXPORT_PROPERTY_QUEUE' with unique index 'idx_pk'. The duplicate key value is (&lt;NULL&gt;).
  The statement has been terminated. 
  </code></pre>
  
  <p>My VB sub where this takes place:</p>
  
  <pre><code>Dim files As String() = Directory.GetFiles(txtFolderPath)
  
              'for each image get file name 
              For Each images As String In files
                  Dim id As String = ""
                  Dim photoID As String = ""
                  Dim position As String = ""
                  For Each str As String In IDS
  
                      If Path.GetFileNameWithoutExtension(sKey).Contains(str) Then
                          id = str
                      End If
                      Log("Property ID" &amp; id)
                      For Each value As String In PhotoIDS
                          photoID = value
  
                      Next
                      For Each URL As String In fullURL
                          fullURLIndex = URL
                      Next
                  Next
                  'AWS upload
                  Try
                      utility.Upload(txtFolderPath &amp; sKey, bucket)
                  Catch
                      needsToExitSub = True
                      Dim cmdSetError As New SqlCommand("ETSP_UPDATE_PHOTO_URLS")
                      cmdSetError.CommandType = CommandType.StoredProcedure
                      cmdSetError.Parameters.AddWithValue("@stype", "L")
                      cmdSetError.Parameters.AddWithValue("@surl", fullURLIndex)
                      cmdSetError.Parameters.AddWithValue("@status", 3)
                      cmdSetError.Parameters.AddWithValue("@pk_photo_id", photoID)
                      Log("pk_photo_id (CATCH): " &amp; photoID)
                      cmdSetError.Parameters.AddWithValue("@bactive", 1)
                      cmdSetError.Parameters.AddWithValue("@property_id", id)
                      cmdSetError.Parameters.AddWithValue("@client_id", clientIDs)
                      conn.Open()
                      cmdSetError.Connection = conn
                      cmdSetError.ExecuteNonQuery()
                      Log(" - ERROR 4 : File : " &amp; sKey &amp; " Image ID : " &amp; photoID &amp; " Has NOT been uploaded to " &amp; bucket &amp; " , URL: " &amp; fullURLIndex)
                      conn.Close()
                      If needsToExitSub = True Then
                          Exit Sub
                      End If
                  End Try
  
                  'Make files public - check this
                  Dim cannedACL As S3CannedACL = S3CannedACL.PublicRead
                  Dim fileNameOnly As String = Path.GetFileNameWithoutExtension(sKey)
                  Dim token As String = fileNameOnly.Remove(fileNameOnly.LastIndexOf("_"c))
                  Dim number As New String(token.SkipWhile(AddressOf [Char].IsLetter).ToArray())
  
                  'Run stored procudure and update if uploaded
                  Dim cmdSet As New SqlCommand("ETSP_UPDATE_PHOTO_URLS")
                  cmdSet.CommandType = CommandType.StoredProcedure
                  cmdSet.Parameters.AddWithValue("@stype", "L")
                  cmdSet.Parameters.AddWithValue("@surl", Convert.ToString("www.url.com/" &amp; bucket &amp; "/" &amp; sKey))
                  cmdSet.Parameters.AddWithValue("@status", 2)
                  cmdSet.Parameters.AddWithValue("@pk_photo_id", photoID)
                  Log("pk_photo_id (TRY): " &amp; photoID)
                  cmdSet.Parameters.AddWithValue("@bactive", 1)
                  cmdSet.Parameters.AddWithValue("@property_id", id)
                  cmdSet.Parameters.AddWithValue("@client_id", clientIDs)
                  conn.Open()
                  cmdSet.Connection = conn
                  cmdSet.ExecuteNonQuery()
  
                  conn.Close()
              Next
              Log(" - File : " &amp; sKey &amp; " has been uploaded to AWS S3 bucket: " &amp; bucket)
          Catch ex As System.NullReferenceException
              Log("ERROR 5 : " &amp; ex.Message)
          Catch ex As Exception
              Log("ERROR 6 : " &amp; ex.Message)
              Exit Try
          End Try
  </code></pre>
  
  <p>So the images downloads file to my computer in the correct folder, then it uploads it also to the correct folder but then when it comes to update the database to update new url and the other parameters it gives the error, now i think it is because the <code>Property ID :</code> is made null.</p>
  
  <p>Why would it get the correct <code>Property ID :</code> for lets say 8 images then get a null for a while and then again get the correct <code>Property ID :</code>. and how can i fix this.</p>
  
  <p>C# help welcome</p>