0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by ChrisPadgham
0

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.

Edited by ChrisPadgham: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.