I have two forms "Sales" and "PurCh". The datagridview in the Sales form is being populated by a stored procedure that is carried out when the form loads and it works perfectly. But the datagridview from the "PurCh" form has refused to populate when the form loads. I initially thought the load event was not firing but then tested it by placing a message box which at runtime popped up. I dont know whats wrong with my code.
Here is the code on the sales form
Imports System.Data.OleDb
Public Class Sales
Dim con As New OleDbConnection
Private Sub Sales_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Connection String
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ABCFarm.mdb"
con.Open()
RefreshDgv()
End Sub
Private Sub RefreshDgv()
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Sales ", con)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
dgvSales.DataSource = dt
'close connection
con.Close()
End Sub
Here is my code for PurCh Form
Imports System.Data.OleDb
Public Class PurCh
Dim con As OleDbConnection
Private Sub PurCh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Connection String
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ABCFarm.mdb"
con.Open()
RefreshDgv()
End Sub
Private Sub RefreshDgv()
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Purchases ", con)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
dgvPurchase.DataSource = dt
'close connection
con.Close()
End Sub
End Class
Please help me. im writting my Final diploma exams and have been instructed to write a program with VB.net 2008 and Access DB 2000 to Manage a Poultry farm.
Thanks