Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
  Dim con As New SqlClient.SqlConnection("data source=GOLDA2\GOLDA;initial catalog=school;Integrated Security=True")
   Dim sql As String = "Select * from fees where particulars=" & "'DataGridView1.Rows(0).Cells(1).Value'" & ""
        Dim dataadapter As New SqlDataAdapter(sql, con)
        Dim ds As New DataSet()
        con.Open()
        dataadapter.Fill(ds, "fees")
        con.Close()
           For j As Integer = 0 To DataGridView1.RowCount - 1
            If DataGridView1.Rows(j).Cells(1).Value = "Lab" Then
                DataGridView1.Rows(j).Cells(2).Value = ds.Tables("fees").Rows(j).Item(2)
                  End If
        Next


    End Sub





 when i run the above code in VB.net it shows that "There is no row at position 0."

After running this code did you check there is table in dataset? And table has rows?

yes there is a table with 2 rows

If it is crashing at line 10 then there isn't any rows in the dataset. Going by your SQL statement I'm not surprised as it is incorrect. Your statement as it appears above will be executing as:

Select * from fees where particulars='DataGridView1.Rows(0).Cells(1).Value'

I strongly doubt you have any row in your database that has 'DataGridView1.Rows().Cells(1).Value' in it. Change it to:

Dim sql As String = "Select * from fees where particulars='" & DataGridView1.Rows(0).Cells(1).Value & "';"
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.