title: Execute non-query question with dataset results
body: <p>I have a fun project that involves VB.net winform app. This applications uses datasets for the forms.  Three tables will be effected Shift_Log (SL), Problem_Log (PL) and Service_Request (SR). If the user changes the log dates on the (SL) so that the (PL) no longer agrees with the error time. I need to remove the foreign key from the (PL) and (SR) tables. I have not tested this yet. I have a couple of questions before I do.</p>
  <ol>
  <li><p>What if there are no records to update in the second update (SR)sql command?</p>
  </li>
  <li><p>do I need to refresh the Dataset after this is executed.</p>
  <pre><code> Public Function UPD_PL_Check(ByVal Shift_Key As String, ByVal SL_Begin As DateTime, SL_End As DateTime) As Integer
  
   ' Get rows from Laser Status Info
   Dim query As String = &quot;SELECT Status_Key FROM [dbo].[Laser_Status_Info]  &quot; &amp;
               &quot; WHERE [Shift_FKey] = &quot; &amp; Shift_Key &amp;
               &quot; AND [Err_time] NOT Between &quot; &amp; SL_Begin &amp; &quot; AND &quot; &amp; SL_End &amp; &quot;;&quot;
  
   Dim dt As DataTable = New DataTable()
   Using conn As SqlConnection = New SqlConnection(My.Settings.LaserMaintLogConnectionString)
       conn.Open()
       Try
           Dim da As SqlDataAdapter = New SqlDataAdapter(query, conn)
           da.Fill(dt)
       Catch ex As Exception
           MessageBox.Show(&quot;Error occured! : &quot; &amp; ex.Message)
       Finally
           conn.Close()
       End Try
   End Using
  
   Dim rowsAffected As Integer = dt?.Rows.Count
  
   If rowsAffected = 0 Then Return rowsAffected
  
   ' Update the Problem log
   For Each i In dt?.Rows
       Using conn As SqlConnection = New SqlConnection(My.Settings.LaserMaintLogConnectionString)
           conn.Open()
           Dim Status_Key As String = dt.Rows(i)(&quot;Status_Key&quot;)
           Try
               Dim PL_query As String =
                &quot;UPDATE [dbo].[Laser_Status_Info] &quot; &amp;
                &quot;   SET [Shift_FKey] = '' &quot; &amp;
                &quot; WHERE [Status_Key] = '&quot; &amp; Status_Key &amp; &quot;';&quot;
               Using Cmd As New SqlCommand(query, conn)
                   rowsAffected = Cmd.ExecuteNonQuery()
               End Using
  
           Catch ex As Exception
               MessageBox.Show(&quot;Error occured! : &quot; &amp; ex.Message)
           End Try
  
           ' Update Service request
           Try
               Dim PL_query As String =
                &quot;UPDATE [dbo].[Laser_Maint_Log] &quot; &amp;
                &quot;   SET [SR_Shift_Key] = '' &quot; &amp;
                &quot; WHERE [SR_Status_Key] = '&quot; &amp; Status_Key &amp; &quot;';&quot;
               Using Cmd As New SqlCommand(query, conn)
                   rowsAffected = Cmd.ExecuteNonQuery()
               End Using
           Catch ex As Exception
               MessageBox.Show(&quot;Error occured! : &quot; &amp; ex.Message)
           End Try
           conn.Close()
       End Using
   Next
  
   Return rowsAffected
  </code></pre>
  <p>End Function</p>
  </li>
  </ol>