Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

trying to populate datagrid with data from database

$
0
0
hi am trying to populate a datagrid with data from my database using a search function but i get this error
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

this my code
  conn.Open()
        searchresults = False
        Dim sql, ids As String
        ids = "%" + id + "%"
        sql = "SELECT * FROM products WHERE productid like  '" & ids & "'"
        cmd = New MySqlCommand(sql, conn)
        Dim rd As MySqlDataReader
        rd = cmd.ExecuteReader
        Dim i As Integer

        While rd.Read
            DataGridView1.Rows(i).Cells(1).Value = rd.Item("productname")
            DataGridView1.Rows(i).Cells(0).Value = rd.Item("productid")
            DataGridView1.Rows(i).Cells(2).Value = rd.Item("sellingprice")

            i = i + 1
        End While
        rd.Close()
        conn.Close()
        searchresults = True


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>