Dear Experts

Data in Table1 is as follows

Code-------product--------weight
1-------------Apple----------2.00
2-------------Mango---------3.25
3-------------Banana---------6.50


Then I have Datagridview with three columns same as

Code, procuct, weight

I have following codes

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        str = "SELECT desc1,weight FROM master where code =" & Val(DataGridView1.Rows(0).Cells(0).Value)
        dt = GetTable(str)

        If dt.Rows.Count > 0 Then
            DataGridView1.Rows(0).Cells(1).Value = Trim(dt.Rows(0).Item(0))
            DataGridView1.Rows(0).Cells(2).Value = Trim(dt.Rows(0).Item(1))
        End If
    End Sub

When I enter 1 in row(0).cells(0) then other two columns fill automatically, but when enter 2 in next row then nothing retreived from database

I think this line should me modified as current row and current column

str = "SELECT desc1,weight FROM master where code =" & Val(DataGridView1.Rows(0).Cells(0).Value)

Please help

You are always retrieving and displaying the values for the first row because you are using a constant (o) in the row references

Rows(0)

you need to replace this with a variable that holds the ordinal position of the row you wish to retrieve.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.