0
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."
3
Contributors
3
Replies
7
Views
4 Years
Discussion Span
Last Post by hericles
0

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

0

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 & "';"
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.