Question Display value in Datagridview Columns

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
Dear Sir,

Datagridview1 has three columns as

S.No-------Porducts--------Price

When I enter s.no in column1 then product name and price must display in relevant columns as

S.No-------Porducts--------Price
1------------Mango---------12

I wrote folloiwng codes as example
Please help

VB.NET:
str = "SELECT * FROM products where sno =" & Val(DataGridView1.Rows(1).Cells(0).Value) 
        cmd = New SqlClient.SqlCommand(str, con)
        da = New SqlClient.SqlDataAdapter(cmd)
        dt = New DataTable
        da.Fill(dt)
        If dt.Rows.Count > 0 Then

 DataGridView1.Rows(1).Cells(2).Value = Val(dt.Rows(1).Item(0))
            DataGridView1.Rows(1).Cells(3).Value = Val(dt.Rows(1).Item(1))
end if
 
Last edited:
You haven't told us what the problem is. Is there an error? Are the wrong values displaying? Are no values displaying?

I think it might have something to do with your row reference, since I have no other information to go on. After you fill the datatable you reference dt.Rows(1) -- assuming your select statement returns with only one result you should be referencing dt.Rows(0) to see the first (and only row?) in the datatable.

Also, which event is trying to perform this 'select and edit'. Depending on which event you are using it might mean that there is more information available.
 
Back
Top