2016-04-09 39 views
0

我正在使用此代码从数据表中找出最近的值。应用程序在循环之间冻结

For Each row As DataGridViewRow In DataGridView2.Rows 
     ToolStripProgressBar1.Value = ToolStripProgressBar1.Value + 1 
     f = 0 
     Using dbconnn As New OleDbConnection(connString) 
      dbconnn.Open() 
      While f <> 1 
       Dim query1 As String = "Select [Alloted_Operator], [Avg_Eff] from ASkill_Matrix2 where [Operation_Type] = '" & row.Cells("Operation_Type").Value & "' and [Avg_Eff] between " & Double.Parse(row.Cells("Req_perf").Value - a) & " and " & Double.Parse(row.Cells("Req_perf").Value + a) & " and [Alloted_Operator] not in (select All_Opr from A) " 
       Using cmd As New OleDbCommand(query1, dbconnn) 
        Using reader1 = cmd.ExecuteReader 

         'If reader1.HasRows Then 
         If reader1.Read() Then 
          f = 1 
          'MessageBox.Show(i) 
          row.Cells("All_Opr").Value = reader1.GetValue(0) 
          row.Cells("Opr_Eff").Value = reader1.GetValue(1) 
          row.Cells("Exp_Prod").Value = Convert.ToDouble((60 * row.Cells("Opr_Eff").Value)/(row.Cells("Oprn_SAM").Value * 100)) 
          row.Cells("Balance").Value = Convert.ToInt64(row.Cells("Exp_Prod").Value - Convert.ToInt64(Label1.Text)) 
          row.Cells("Rem_Eff").Value = Convert.ToInt64(row.Cells("Opr_Eff").Value - row.Cells("Req_perf").Value) 
          Dim query29 As String = "insert into A ([Machine_Type], [Attatchment], [All_Opr]) Values ('" & CStr(row.Cells("Machine_Type").Value) & "', '" & CStr(row.Cells("Attatchment").Value) & "', '" & CStr(row.Cells("All_Opr").Value) & "')" 
          Using cmd1 As New OleDbCommand(query29, dbconnn) 
           cmd1.ExecuteNonQuery() 
          End Using 
          If row.Cells("Rem_Eff").Value >= 20 Then 
           Dim query3 As String = "insert into Temp_Av_Opr ([Machine_Type], [Attatchment], [All_Opr],[Opr_Eff]) Values ('" & CStr(row.Cells("Machine_Type").Value) & "','" & CStr(row.Cells("Attatchment").Value) & "', '" & CStr(row.Cells("All_Opr").Value) & "', '" & CStr(row.Cells("Rem_Eff").Value) & "')" 
           Using cmd2 As New OleDbCommand(query3, dbconnn) 
            cmd2.ExecuteNonQuery() 
           End Using 
          End If 
         Else 
          a += 1 
         End If 
        End Using 
       End Using 
      End While 
     End Using 
    Next 

,这是我的冻结窗口在第二次运行应用

请帮我在这或PLZ建议我任何其他方法来这样做。 谢谢

回答

0

首先要做的事情是不使用了循环之前移动第一循环里的任何东西(确实dbconn)。第二,如果f永远不会被赋值为1,您的第二个循环将永远运行。