title: Another way to Optimize the results of a SQL VB.NET
body: <p>I am experiencing some slowness problems is trying to refresh my datagrid with this code, 
  What I'm trying to do is manipulate the columns ACROSS variable (selltype_code).</p>
  
  <pre><code>objConn.Open()
  
              Dim sqlConn As String = ("SELECT item_code, item_name, item_quantity, selltype_code, item_selldetail FROM qa_items")
              Dim objDataAdapter As New MySqlDataAdapter(sqlConn, objConn)
              Dim ds As New DataSet
  
              objDataAdapter.Fill(ds, "items")
  
              'Fill datagridview with FOR CICLE
              For i As Int16 = 0 To ds.Tables("items").Rows.Count - 1
                  If ds.Tables("items").Rows(i).Item("selltype_code") = 1 Then
                      With Me.resultitems_seach_item
                          .Item(3, i).Style.ForeColor = ColorTranslator.FromOle(RGB(39, 74, 109)) 'Color para Precio
                          .Item(3, i).Value = ds.Tables("items").Rows(i).Item("item_selldetail") 'Valor para Precio
                          .Item(4, i).Style.ForeColor = Color.DarkGray
                          .Item(4, i).Value = "---"
                          .Item(5, i).Style.ForeColor = Color.DarkGray
                          .Item(5, i).Value = "---"
                          .Item(6, i).Style.ForeColor = Color.DarkGray
                          .Item(6, i).Value = "---"
                      End With
                  ElseIf ds.Tables("items").Rows(i).Item("selltype_code") = 2 Then
                      With Me.resultitems_seach_item
                          .Item(3, i).Style.ForeColor = Color.DarkGray
                          .Item(3, i).Value = "---"
                          .Item(4, i).Style.ForeColor = Color.DarkGray
                          .Item(4, i).Value = "---"
                          .Item(5, i).Style.ForeColor = ColorTranslator.FromOle(RGB(39, 74, 109)) 'Color para Precio
                          .Item(5, i).Value = ds.Tables("items").Rows(i).Item("item_selldetail")
                          .Item(6, i).Style.ForeColor = Color.DarkGray
                          .Item(6, i).Value = "---"
                      End With
                  ElseIf ds.Tables("items").Rows(i).Item("selltype_code") = 3 Then
                      With Me.resultitems_seach_item
                          .Item(3, i).Style.ForeColor = Color.DarkGray
                          .Item(3, i).Value = "---"
                          .Item(4, i).Style.ForeColor = ColorTranslator.FromOle(RGB(39, 74, 109)) 'Color para Precio
                          .Item(4, i).Value = ds.Tables("items").Rows(i).Item("item_selldetail")
                          .Item(5, i).Style.ForeColor = Color.DarkGray
                          .Item(5, i).Value = "---"
                          .Item(6, i).Style.ForeColor = Color.DarkGray
                          .Item(6, i).Value = "---"
                      End With
                  Else
                      With Me.resultitems_seach_item
                          .Item(3, i).Style.ForeColor = Color.DarkGray
                          .Item(3, i).Value = "---"
                          .Item(4, i).Style.ForeColor = Color.DarkGray
                          .Item(4, i).Value = "---"
                          .Item(5, i).Style.ForeColor = Color.DarkGray
                          .Item(5, i).Value = "---"
                          .Item(6, i).Style.ForeColor = ColorTranslator.FromOle(RGB(39, 74, 109)) 'Color para Precio
                          .Item(6, i).Value = ds.Tables("items").Rows(i).Item("item_selldetail")
                      End With
                  End If
  
              Next i
  
              objConn.Close()
  </code></pre>