Receiving System.NullReferenceException with my code:
Private Sub dsplay()
ds.Clear()
dgv_tran.DataSource = ds
da = New OleDbDataAdapter("SELECT p.prod_id, p.prod_name, b.cost_ave " & _
"FROM tbl_products p " & _
"INNER JOIN tbl_balance b " & _
"ON p.ID = b.p_id", con)
da.Fill(dt)
dgv_tran.DataSource = ds
dgv_tran.DataMember = "table1"
call dgv_tran_CellClick(Nothing,Nothing)
end sub
Private Sub dgv_tran_CellClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgv_tran.CellClick
Try
Dim i As Integer = dgv_tran.CurrentRow.Index 'error starts in this line
txtid.Text = dgv_tran.Item(0, i).Value
txtname.Text = dgv_tran.Item(1, i).Value
txtcost.Text = dgv_tran.Item(2, i).Value
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
My datagridview displays the data that I need, I can proceed with the project just fine when I remove the MessageBox.Show(ex.ToString) but I can't just ignore this error can I? Already spent 4hours trying to figure this one out. Any help pointing out the problem would be much appreciated.